0

I've been working on a way to determine if a user likes a particular page so a tab on that page can be fangated or not. I didn't want to prompt the user for authorization for user_likes, so I avoided the JS SDK and used the PHP SDK:

<?php
require 'src/facebook.php';
$app_id = "...";
$app_secret = "...";
$facebook = new Facebook(array('appId' => $app_id, 'secret' => $app_secret, 'cookie' => true));
$signed_request = $facebook->getSignedRequest();
$like_status = $signed_request["page"]["liked"];
/* testing response */
if ($like_status) {
    /* liked content */
} else {
    /* not liked content */
}
?>

My problem is signed_request is passed only when the code is on the FB tab--if I hit the PHP page outside of FB, I get nothing. I wondered if there's a way to get this user info outside of Facebook.com.

Jeremy Schultz
  • 579
  • 1
  • 6
  • 26

2 Answers2

0

You can try saving the signed_request in a session or cookie so you can use it until it expires. After which, the user will have to come through the tab again to renew it. Naturally, if you are planning to use cookies, you should keep the signed_request decoded so no one can find and use the access_token from the cookie.

Niraj Shah
  • 15,087
  • 3
  • 41
  • 60
  • Thanks, I thought of this as well but it still requires an authentication of some kind which I'd like to avoid. – Jeremy Schultz Aug 02 '12 at 13:58
  • Not really. The `signed_request` is passed regardless. You only need authentication if you want to query the API for something other than the Like Gate. – Niraj Shah Aug 02 '12 at 16:32
  • I mean there will come a point where the user has to perform an action (visit the tab) for the signed_request to be valid. – Jeremy Schultz Aug 02 '12 at 20:05
  • That's correct - the user will have to go via the tab to be able to get a valid signed_request containing the Page Like information. There is no other way to get this information unless you get the user to login and query the API for the Like information using FQL. – Niraj Shah Aug 03 '12 at 15:50
0

Sounds like this isn't really feasible outside of the Facebook tab. We've begun deploying our tabs in PHP in order to pull this data without an action on the user's part.

Thanks!

Jeremy Schultz
  • 579
  • 1
  • 6
  • 26