Why does the facebook photo album return an empty array?

Asked

Viewed 49 times

1

I’m using Facebook SDK with Laravel 4. I need to return the images of any user who logs in via Facebook.

When I use the user, who is the administrator of the APP on Facebook, the images and albums are returned normally.

However, when I try to do this with any non-administrator user, an empty array is returned.

The code I’m using is as follows::

$session = new FacebookSession(Session::get('facebook.token'));

$request = new FacebookRequest(
    $session,
    'GET',
    '/me/albums',
    ['fields' => 'name,photos.limit(20){source},id']
);

$response = $request->execute()->getGraphObject();

$imagesOfAllAlbums = [];

foreach ($response->asArray() as $albuns) {

   foreach ($albuns as $k => $album) {

    if (empty($album->photos)) continue;

    foreach ($album->photos as $images) {

        foreach ($images as $image) {

            if (empty($image->source)) continue;

            $imagesOfAllAlbums[$album->name][] = $image->source;
        }
        }
   }
}

count($imagesOfAllAlbums); // 0

In the first case, it would return this:

[
   'Nome do Album' => [
         'imagem_1.jpg',
         'imagem_2.jpg',
    ]
]
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.