2

So I have a page on facebook that has some tabs via apps that I've made. They are promotional tabs. For some of those tabs I'd like to show alternate teaser content until they have "liked" the page. I am NOT using PHP, so JS or Ruby only please.

I do not need to do any fb connect stuff, nor do I need to know if they like the app/page from my website... all of what I need will take place on facebook via iframe.

Thanks!

[edit: check out redbull's fan page: http://www.facebook.com/redbull this is what I would like to do]

CloudMagick
  • 2,428
  • 2
  • 23
  • 20

1 Answers1

0

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: enter image description here

Community
  • 1
  • 1
CloudMagick
  • 2,428
  • 2
  • 23
  • 20
  • hi cloudMagick. Sorry for that question, but what are you sending in the "signed_request"? Do you need a token from that user? Where did you get that? many, many thanks in advance. This issue is very rare here on stackoverflow, for all on ruby – Jan Jun 21 '13 at 10:15