简体   繁体   中英

Facebook reveal-tab / like-gate for an iframe app without PHP (Rails or javascript, please)

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]

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:在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM