Facebook Connect: How can I get a logged in user's info into a PHP object?
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';
开发者_JAVA百科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();
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.
精彩评论