Facebook SDK photos return empty array

I use this to get user photos, but always print_ran empty 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 is an print_rarray full of data, but not the photo information I'm looking for.

Any ideas?

+3
source share
3 answers

When you get a facebook session, you also get an access token. You must use it to make valid api requests. Everything that is not public information requires this token. Usage example:

$session = $facebook->getSession();
// var_dump($session) to see it content
$facebook->api('/me/photos?access_token=' . $session['access_token']); 

If you do this, you are still receiving blank data, this user may not have photos.

Good luck

+1
source

. :

$facebook->api('/me/albums?access_token=' . $session['access_token']);

, !

+2

Try https://graph.facebook.com/ $ album_id / photos

I'm not sure why me / photos returns an empty array. This probably means something else, there may be photographs in which I am marked, or something else. For me, too, it returns an empty array sequentially. but when I try to access graph.facebook.com/$album_id/photos, then I get an array of all the photos in this album.

0
source

Source: https://habr.com/ru/post/1781796/


All Articles