Ad

Retrieve Facebook Likes After October 2013 Breaking Changes

- 1 answer

from https://developers.facebook.com/roadmap/

"Currently the API returns all likes by default. After the migration, fetching a user's likes via the Graph API will return 25 results at a time. We've added pagination to the results so you can page through to all of a user's likes."

I have read the paging how-to here https://developers.facebook.com/blog/post/478/ but still it is not very clear to me which is the best practice to use:

1) The document says that "With the Graph API, when there is more data available, you will notice that paging links are provided:", but at the moment (no limit) I'm getting the paging links even if all the results are already retrieved in the first page. Do I have to check manually the number of results of the following page to verify if it is empty?

2) The document also says "You might notice that the number of results returned is not always equal to the “limit” specified. This is expected behavior. Query parameters are applied on our end before checking to see if the results returned are visible to the viewer. Because of this, it is possible that you might get fewer results than expected.". This should not affect likes retrieving, am I right? I think it is not possible that some likes are viewable and some others not.

Thanks.

Ad

Answer

I'll try to answer to myself.

1) Yes, I have to check manually, I just did something like this (in this example I retrieve music likes)

$fb_music_likes_ar = array();
$end = 0;
$offset = 0;
while ($end === 0){
    $temp_ar = $facebook->api('/me/music?limit=25&offset='.$offset);
    $fb_music_likes_ar = array_merge($fb_music_likes_ar, $temp_ar['data']);

    $offset = $offset+25;

    if (count($temp_ar['data']) < 25){
        $end = 1;
    }
}

This of course takes more time than before; I don't understand the reason of the change, if I need all the likes I will end up doing several calls and I don't think it is more efficient... Maybe we can use batch processing to launch several calls?

2) I don't think this is affecting likes retrieving

Ad
source: stackoverflow.com
Ad