Asynchronously get user data in facebook tab?

Posted by Kristoffer Nolgren on Stack Overflow See other posts from Stack Overflow or by Kristoffer Nolgren
Published on 2013-10-17T14:26:39Z Indexed on 2013/10/17 15:55 UTC
Read the original article Hit count: 182

Using the php sdk, I check if a user inside a tab likes the corresponding page.

If i put the following code inside index.php and use that page as my page-tab-url,

<?php
require_once("facebook/facebook.php");

// Create our application instance
// (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => '1399475990283166',
  'secret' => 'mysercret',
  'cookie' => true
));

$signed_request = $facebook->getSignedRequest();
echo $signed_request['page']['liked'];
?>

it outputs '1'.

I would like to achieve this asynchronously instead, so I put the php in a separate file and try to access it using ajax instead

$http.post('/facebook/likes.php').
    success(function(data){
        console.log(data);
    }).error(function(data){
        console.log(data);
        }
    );

This sample is using angular, but what javascript library i'm using probably doesn't matter.

When I access the info with javascript Facebook doesn't seem to get the info that I liked the page. Adding a print_r($facebook); on the page I'm retreiving the same values as if i'm not in a facebook-tab:

(
    [sharedSessionID:protected] => 
    [appId:protected] => 1399475990283166
    [appSecret:protected] => 679fb0ab947c2b98e818f9240bc793da
    [user:protected] => 
    [signedRequest:protected] => 
    [state:protected] => 
    [accessToken:protected] => 
    [fileUploadSupport:protected] => 
    [trustForwarded:protected] => 
)

Can I access theese values asynchronosly somehow?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about facebook