0

I have a Facebook "landing tab" that is setup, and I have installed another tab that I would like to be activated after a fan clicks the "like" button. I have searched the Internet and come up with a mix of JavaScript and PHP SDK code but nothing has really worked for me so far.

I guess there are two main problems:

  1. After the fan initially visits the site (they go directly to the landing tab) and clicks the "like" button, I would like the iframe to redirect to the other tab that I have created. I tried a simple JavaScript redirect (windows.location = "URL") and that changed it to the URL I wanted but not within the Facebook iframe - obviously it was also not called by the clicking like action.

  2. If I can get the above working, the next problem is that once the like button is clicked I want the second tab to always be the default for the user.... Right now after the user hits "like" it directs to the wall page and again when the visitor returns to the page it is the wall page. If I get problem #1 working with the redirect will it then always default to that second tab or will it still be sending people to the wall when they revisit the page?

Here is some code I found. Both JavaScript SDK and PHP SDK. Where am I going wrong?

FB.Event.subscribe('edge.create',
    function(response) {
        location.href = 'URLofSecondtab';
    }
);

The above code is what I have been told is the Facebook event handler for like in JavaScript.

<div id="fb-root"></div>

<script type="text/javascript">
    window.fbAsyncInit = function() {
        FB.init({appId: 'idOfLandingTab', status: true, cookie: true, xfbml: true});
        //FB.Canvas.setSize({ width: 520, height: 1500 });
        FB.Event.subscribe('edge.create',
            function(response) {
                alert('like!');
                // put redirect code here eg
                window.location = "URLofSecondtab";
            }
        );
    };

    //Load the SDK asynchronously
    (function() {
        var e = document.createElement('script'); e.async = true;
        e.src = document.location.protocol +
          '//connect.facebook.net/en_US/all.js';
        document.getElementById('fb-root').appendChild(e);
    }());
</script>

I have found the PHP SDK and have not been able to implement:

<?php
    // Sample PHP code to customize the a Facebook Fan Page iFrame Application
    // Refer to http://www.hyperarts.com/blog/customizing-facebook-iframe-application-    signed_request_reveal_tab

    require 'facebook.php';

    $app_id = "APP_ID_HERE"; //which app id? the landing tab or the second tab that I want     //redirected?
    $app_secret = "APP_SECRET_HERE";
    $facebook = new Facebook(array(
        'appId' => $app_id,
        'secret' => $app_secret,
        'cookie' => true
    ));


    $signed_request = $facebook->getSignedRequest();

    $page_id = $signed_request["page"]["id"];
    $page_admin = $signed_request["page"]["admin"];
    $like_status = $signed_request["page"]["liked"];
    $country = $signed_request["user"]["country"];
    $locale = $signed_request["user"]["locale"];

    echo "<br>page id = $page_id";
    echo "<br>page admin = $page_admin";
    echo "<br>like status = $like_status";
    echo "<br>country = $country";
    echo "<br>locale = $locale";
?>

Which tab URL and app id is required in what location? And what kind of code (the JavaScript or PHP code)?

Heidelbergensis
  • 475
  • 2
  • 5
  • 18
ristenk1
  • 435
  • 3
  • 6
  • 26

4 Answers4

1

If you are using facebook page tab, then parameter will work like the following(PHP):

$signed_request=$_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2); 
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
//to get page id use this => $data["page"]["id"]
//to get liked or unlike page => $data["page"]["liked"]  = this will return 1 if 
//liked else blank

More info: https://developers.facebook.com/docs/appsonfacebook/pagetabs/ scroll to the end and read this para =>Integrating with Facebook APIs

DisplayName
  • 3,093
  • 5
  • 35
  • 42
0

I think your problem can be resolved with this:

How to check if a user likes my Facebook Page or URL using Facebook's API

On that page he has this code on Jason Siffring's answer:

if($signed_request = parsePageSignedRequest()) {
    if($signed_request->page->liked) {
      echo "This content is for Fans only!";
    } else {
      echo "Please click on the Like button to view this tab!";
    }
  }

Instead of those 'echo's you could echo 'window.document.location.replace("SOMEWHERE")'

Community
  • 1
  • 1
0

After the user likes the page it will refresh, so at this point you could use your $page_id var to detect if the user had liked the paged and then redirect the iframe's parnt, the value of the $page_id will be 1, so in the body of your document you could do this:

<? if($page_id){ ?>
<script>window.top.location.href = "http://www.facebook.com/FANPAGE_USERNAME?sk=app_APPID";</script>
<? } ?>
miguelglz
  • 417
  • 1
  • 4
  • 16
0

Landing tabs will be disabled with timeline for pages, on March 30th

Edit: that is if you are talinkg about about fan pages, if not nevermind.

dythffvrb
  • 177
  • 1
  • 9