Got a working solution without PHP. Thanks to dwarfy at this post for inspiration.
This is NOT a JS solution, and I don't think that what I am interested in doing can be done with JS because it would involve cross-site scripting, which is a no-no. In short, you have to digest signed_request
in one way or another if you want to tell if someone likes your page via your iframed app.
So my app is Ruby on Rails. On the FB side I kept things in sandbox mode and worked/tested in prod. Not sure how to get a suitable local environment to test. anyway...
- I installed/required the gem fbgraph.
- created a gate controller & views:
rails g controller gate index fbindex
app/controllers/gate_controller.rb:
class GateController < ApplicationController
def index
end
def fbindex
app_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
@signed_request = FBGraph::Canvas.parse_signed_request(app_secret, params[:signed_request])
end
end
app/views/gate/index.html.erb:
<h1>Gate#index</h1>
<p>Find me in app/views/gate/index.html.erb</p>
<form action="/gate/fbindex" method="post">
signed request: <input type="text" name="signed_request">
<input type="submit"/>
</form>
app/views/gate/fbindex.html.erb:
<h1>Gate#index</h1>
<p>Find me in app/views/gate/fbindex.html.erb</p>
<%= @signed_request.inspect %>
<% if @signed_request["page"]["liked"] %>
You like me!
<% else %>
You suck, cuz you don't like me
<% end %>
Get your FB settings right:
