Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to pull facebook posts onto my site so that I can save and display it in my own format. I am trying to use the facebook-php-sdk library, found on the Facebook Developer pages. I used the following code after I required the library:

$facebook = new Facebook(array(
'appId'  => 'MY APP ID',
'secret' => 'MY APP SECRET',
));

// Get User ID
$user = $facebook->getUser();
print_r($facebook);
print_r($user);

The print_r into $facebook showed me a full facebook object, so I know its being created properly.

 object(Facebook)#325 (9) { ["sharedSessionID":protected]=> NULL ["appId":protected]=> string(15) "[MYAPPID]" ["appSecret":protected]=> string(32) "[MYAPPSECRET]" ["user":protected]=> int(0) ["signedRequest":protected]=> NULL ["state":protected]=> NULL ["accessToken":protected]=> string(48) "[MYAPPID]|[MYAPPSECRET]" ["fileUploadSupport":protected]=> bool(false) ["trustForwarded":protected]=> bool(false) }

(I took my app id and app secret codes out of the quote above).

However, the print_r into $user displayed

int(0).

What am I missing here?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
188 views
Welcome To Ask or Share your Answers For Others

1 Answer

“What am I missing here?” Authenticating the user. You’re calling getUser(), but until you authenticate, Facebook doesn’t know which user to get details for. I’m also unsure why you’ve missed it, as it’s the example on the GitHub repo for the PHP SDK.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...