Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6042191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:45:46+00:00 2026-05-23T06:45:46+00:00

I am trying to create a Facebook iFrame app. The app should first show

  • 0

I am trying to create a Facebook iFrame app. The app should first show an image and if the user likes the page, he will get access to some content.

I use RoR, therefore I can’t use the Facebook PhP SDK.

Here is my iFrame HTML when the user has not liked the page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<style type="text/css">
body {
width:520px;
margin:0; padding:0; border:0;
font-family: verdana;
background:url(repeat.png) repeat;
margin-bottom:10px;
}
p, h1 {width:450px; margin-left:50px; color:#FFF;}
p {font-size:11px;}
</style>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
</head>
<body>
<div id="container">
<img src="welcome.png" alt="Frontimg">
</div>

And, if the user has liked the page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<style type="text/css">
body {
width:520px;
margin:0; padding:0; border:0;
font-family: verdana;
background:url(repeat.png) repeat;
margin-bottom:10px;
}
p, h1 {width:450px; margin-left:50px; color:#FFF;}
p {font-size:11px;}
</style>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
</head>
<body>
<div id="container">
<img src="member.png" alt="Frontimg">
<p>You liked this page</p>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:45:46+00:00Added an answer on May 23, 2026 at 6:45 am

    UPDATE 21/11/2012
    @ALL : I have updated the example so that it works better and takes into accounts remarks from Chris Jacob and FB Best practices, have a look of working example here


    Hi So as promised here is my answer using only javascript :

    The content of the BODY of the page :

    <div id="fb-root"></div>
    <script src="http://connect.facebook.net/en_US/all.js"></script>
    <script>
      FB.init({
        appId  : 'YOUR APP ID',
        status : true, 
        cookie : true, 
        xfbml  : true  
      });
    </script>
    
    <div id="container_notlike">
    YOU DONT LIKE
    </div>
    
    <div id="container_like">
    YOU LIKE
    </div>
    

    The CSS :

    body {
    width:520px;
    margin:0; padding:0; border:0;
    font-family: verdana;
    background:url(repeat.png) repeat;
    margin-bottom:10px;
    }
    p, h1 {width:450px; margin-left:50px; color:#FFF;}
    p {font-size:11px;}
    
    #container_notlike, #container_like {
        display:none
    }
    

    And finally the javascript :

    $(document).ready(function(){
    
        FB.login(function(response) {
          if (response.session) {
    
              var user_id = response.session.uid;
              var page_id = "40796308305"; //coca cola
              var fql_query = "SELECT uid FROM page_fan WHERE page_id = "+page_id+"and uid="+user_id;
              var the_query = FB.Data.query(fql_query);
    
              the_query.wait(function(rows) {
    
                  if (rows.length == 1 && rows[0].uid == user_id) {
                      $("#container_like").show();
    
                      //here you could also do some ajax and get the content for a "liker" instead of simply showing a hidden div in the page.
    
                  } else {
                      $("#container_notlike").show();
                      //and here you could get the content for a non liker in ajax...
                  }
              });
    
    
          } else {
            // user is not logged in
          }
        });
    
    });
    

    So what what does it do ?

    First it logins to FB (if you already have the USER ID, and you are sure your user is already logged in facebook, you can bypass the login stuff and replace response.session.uid with YOUR_USER_ID (from your rails app for example)

    After that it makes a FQL query on the page_fan table, and the meaning is that if the user is a fan of the page, it returns the user id and otherwise it returns an empty array, after that and depending on the results its show a div or the other.

    Also there is a working demo here : http://jsfiddle.net/dwarfy/X4bn6/

    It’s using the coca-cola page as an example, try it go and like/unlike the coca cola page and run it again …

    Finally some related docs :

    FQL page_fan table

    FBJS FB.Data.query

    Don’t hesitate if you have any question ..

    Cheers

    UPDATE 2

    As stated by somebody, jQuery is required for the javascript version to work BUT you could easily remove it (it’s only used for the document.ready and show/hide).

    For the document.ready, you could wrap your code in a function and use body onload="your_function" or something more complicated like here : Javascript – How to detect if document has loaded (IE 7/Firefox 3) so that we replace document ready.

    And for the show and hide stuff you could use something like : document.getElementById("container_like").style.display = "none" or "block" and for more reliable cross browser techniques see here : http://www.webmasterworld.com/forum91/441.htm

    But jQuery is so easy 🙂

    UPDATE

    Relatively to the comment I posted here below here is some ruby code to decode the “signed_request” that facebook POST to your CANVAS URL when it fetches it for display inside facebook.

    In your action controller :

    decoded_request = Canvas.parse_signed_request(params[:signed_request])
    

    And then its a matter of checking the decoded request and display one page or another .. (Not sure about this one, I’m not comfortable with ruby)

    decoded_request['page']['liked']
    

    And here is the related Canvas Class (from fbgraph ruby library) :

     class Canvas
    
        class << self
          def parse_signed_request(secret_id,request)
            encoded_sig, payload = request.split('.', 2)
            sig = ""
            urldecode64(encoded_sig).each_byte { |b|
              sig << "%02x" % b
            }
            data = JSON.parse(urldecode64(payload))
              if data['algorithm'].to_s.upcase != 'HMAC-SHA256'
              raise "Bad signature algorithm: %s" % data['algorithm']
            end
            expected_sig = OpenSSL::HMAC.hexdigest('sha256', secret_id, payload)
            if expected_sig != sig
              raise "Bad signature"
            end
            data
          end
    
          private
    
          def urldecode64(str)
            encoded_str = str.gsub('-','+').gsub('_','/')
            encoded_str += '=' while !(encoded_str.size % 4).zero?
            Base64.decode64(encoded_str)
          end
        end  
    
     end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a link that will share a page on Facebook. So
Trying to create my first iPhone app that would play back audio. When I
I am trying re-create the facebook tagging functionality, where you click on an image
Been trying to create a layout similar to the Android Facebook app (top bar
I trying to create a publish button for an image in my android app,
I'm trying to create a simple iFrame custom tab on my fan page. I'm
Trying to create an android app with Facebook integration, I've gotten to the part
i have a test.php file that will hold a facebook app (iframe based php).
I am trying to create a facebook like website here http://likes.vermilionsite.com/ but when you
Trying to create a QtRuby application, I get the following error: /usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.