Facebook SDK photos returns blank array
I am using this to retrieve user photos however it always print_r
's a blank array:
$facebook = new Facebook(array(
'appId' => 'XXX',
'secret' => 'XXX',
'cookie' => true,
));
if ($facebook->getSession()) {
try {
$profile = $facebook->api('/me/photos');
echo "<pre>";
print_r($profile);
} catch (FacebookApiException $e) {
echo $e->getMessage();
exit();
}
}
else {
$login_url = $facebook->getLoginUrl(array(
'next' => 'XXX',
'cancel_url' => 'XXX',
'req_perms' => 'user_about_me,user_location,user_hometown,user_birthday,user_interests,user_likes,user_photos'
));
echo '<a href="'.$login_url.'">Click here to login</a>';
}
If I use:
$profile = $facebook->api('/me');
It print_r
's an ar开发者_JAVA百科ray full of data but not the photo information I am looking for.
Any ideas?
I was having the same problem. My solution :
$facebook->api('/me/albums?access_token=' . $session['access_token']);
Hope It's not too late !
When you get the facebook session you also receive an access token. You have to use it to make valid api requests. Everything that's not public info require that token. Example of usage:
$session = $facebook->getSession();
// var_dump($session) to see it's content
$facebook->api('/me/photos?access_token=' . $session['access_token']);
If doing this you still get empty data, maybe that user does not have any photos.
Good luck!
Try https://graph.facebook.com/$album_id/photos
I am not sure why me/photos does return empty array. Probably it means something else, may be the photos where I am tagged or some other thing. For me too, it returns empty array consistently. but when I try to access graph.facebook.com/$album_id/photos then I get the array of all the photos in that album..
精彩评论