views:

44

answers:

1

i have been working tirelessly just to get this working, but for some reason, in the following code:

require_once 'facebook-php-sdk/src/facebook.php';

$facebook = new Facebook(FACEBOOK_API_KEY,FACEBOOK_SECRET);

$fb_user = $facebook->getUser();

the variable $fb_user is always null! i was wondering what i am missing in order to get this user and finally be able to get a user's friends list and application list.

thanks for any help!

UPDATE:

here's my new code. still returns null for $fb_user though:

require_once 'facebook-php-sdk/src/facebook.php';

const FACEBOOK_APP_ID   = '130889803597902';
const FACEBOOK_API_KEY  = '56800990331df98bfe358812eb6caf5d';
const FACEBOOK_SECRET   = '59e30217f9efc633253c6832d029ab02';

$facebook = new Facebook(
    array(
      'appId' => FACEBOOK_APP_ID, // application id
      'secret' => FACEBOOK_SECRET, // application secret
      'cookie' => true, // whether to enable cookie support
   )
);

$fb_user = $facebook->getUser();
+1  A: 

The new version of Facebook's PHP SDK is constructed slightly differently:

$facebook = new Facebook(
    array(
      'appId' => FACEBOOK_APPLICATION_ID, // application id
      'secret' => FACEBOOK_APPLICATION_SECRET, // application secret
      'cookie' => true, // whether to enable cookie support
   )
);

The getUser method is probably failing since the class isn't instantiated properly.

Johannes Gorset
the comments are a little redundant, don't you think? :p
Mark
@Mark: I agree, but I thought I'd make extra sure people notice that the api key has been substited for the application id in the new SDK.
Johannes Gorset
@FRKT, thank you so much. I was actually just switching my app to the graph API today, and couldn't get it to authenticate! I was using API key!
Mike Sherov