9
votes

I'm using Facebook Graph API to get all the photos of a user graphPath: me/albums and find something weird with Timeline Photos album.

Photos exist in Timeline album on Facebook, but not returned from API call graphPath/{timeline_photos_album_id}/photos, or they are returned with lower number of photos.

What is the problem?

Logs:

Calling for albums graphPath: me/albums:

.....
{
     "can_upload" = 0;
      count = 3; !!!!!!!!!!!
      "created_time" = "2013-06-18T10:43:27+0000";
      description = cool;
      from = {
                id = 100006100533891;
                name = "Mike Mike";
            };
      id = 1387760311437307;
      link = "https://www.facebook.com/album.php? 
          fbid=1387760311437307&id=100006100533891&aid=1073741829";
      name = "Timeline Photos";
      privacy = everyone;
      type = wall;
      "updated_time" = "2013-06-18T10:47:53+0000”;
 },
 .....

Calling for album photos graphPath/{timeline_photos_album_id}/photos:

{
    data =     (
    );
}
4
Did you checked the permissions and visibility status of each wall posts? If some are restricted to very narrow groups, it may not show in the photo's list. - Simon Boudrias
@SimonBoudrias Good idea! I think permission could be one of the reasons! thank you for highlighting. would give a try :P - xialin
I think the response for graphPath/{timeline_photos_album_id}/photos cannot be correct as it's not a valid JSON... - Tobi

4 Answers

2
votes

I tried the following (with "user_photos" permission) and it works:

Fetch the album photo count for my user:

https://graph.facebook.com/me/albums?fields=id,count&access_token={access_token}

The result is

{
  "data": [
    {
      "id": "{album_id}", 
      "count": 161, 
      "created_time": "2010-11-05T15:41:42+0000"
    }, 
    ....
}

Then query for the photos of this album:

https://graph.facebook.com/{album_id}/photos?fields=id&limit=500&access_token={access_token}

The result is

{
  "data": [
    {
      "id": "{photo_id1}", 
      "created_time": "2013-12-29T09:59:52+0000"
    }, 
    {
      "id": "{photo_id2}", 
      "created_time": "2013-12-17T10:40:26+0000"
    },
    ...
}

I count the correct number of 161 ids in the result. So everything seems to work fine.

You can also test this via FQL:

https://graph.facebook.com/fql?q=select+pid+from+photo+where+album_object_id+=+{album_id}+limit+1000&access_token={access_token}
1
votes

there have been changes in the FB API recently, did you try to add the fields you want to get back in the result from the API? In the past, API always returned "standard fields", newest you always have to provide a list of fields of what you want to have back in the result such as ....fields=name,id...

1
votes

I think you are missing the user_photos permission in the Access Token. The end point: /{timeline_photos_album_id}/photos is working perfectly fine for me when I tried it using the Graph API Explorer to retrieve photos from my Timeline photos album. And, I don't think that it is necessary to provide the fields.

I'll suggest you should try the same using the Graph API Explorer. Just press the Get Access Token button on the top right and check the user_photos permission to test your request.


In case you are getting lesser results, you can try your query using pagination options limit and offset. This sometimes returns more results as compare to normal(nothing about this on docs, just my personal experience). Something like:

{timeline_photo_album_id}/photos?limit=500&offset=0

But again, as you pointed out, there are strange things going on with the API. Take a look at this article. This article refers to it as an expected behavior of the API!