Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

facebook php, how do you use results paging?

Hello i am using the Facebook PHP SDK (v.3.1.1)

I don't understand how to use the results paging url.

I want to get a list of ALL my friends, here is my code

$friends = $fb->api('/me/friends');
/*  
$friend == Array
(
    [data] => Array
    (
       ...
    ),
    [paging] => Array
    (
        [next] => https://graph.facebook.com/me/friends?method=GET&access_token=SOMETHING&limit=5000&offset=5000
    )
*/
if (!empty($friends['paging']['next']))
{
    $friends2 = $fb->api($friends['paging']['next']);
    //doesn't work
}
like image 896
max4ever Avatar asked Nov 21 '11 11:11

max4ever


People also ask

How Facebook’s Infinite page scroll changed the way we use pagination?

One such UI that has changed pagination forever is the infinite page scroll. The Facebook uses it in its wall which is the primary UI for the users. The infinite scroll replaces the traditional pagination design with page numbers and navigation links. Displaying paginated results with the usual navigation link is almost outdated.

What is Facebook doing with PHP?

The modified version of PHP has allowed Facebook to push their own improvements to the language and even flowed back into the main PHP repo. When Facebook was first created, Mark Zuckerberg used PHP. As Facebook expanded PHP was still used as everyone who was developing for Facebook, knew PHP. Now Facebook

What is pagination in PHP and MySQL?

This is where pagination in PHP and MySQL comes in handy. You can display the results over a number of pages, each linked to the next, to allow your users to browse the content on your website in bite-sized pieces. The code below first connects to the database.

Can We display all the results on one page?

But its is not good idea to display all the results on one page. So we can divide this result into many pages as per requirement. Paging means showing your query result in multiple pages instead of just put them all in one long page.


Video Answer


1 Answers

All of the previous responses are valid.

Here is the way I do, to get all the "next" result with the Graph API:

Note that I don't get "previous" results.

function FB_GetUserTaggedPhotos($user_id, $fields="source,id") {
    $photos_data = array();
    $offset = 0;
    $limit = 500;

    $data = $GLOBALS["facebook"]->api("/$user_id/photos?limit=$limit&offset=$offset&fields=$fields",'GET');
    $photos_data = array_merge($photos_data, $data["data"]);

    while(in_array("paging", $data) && array_key_exists("next", $data["paging"])) {
        $offset += $limit;
        $data = $GLOBALS["facebook"]->api("/$user_id/photos?limit=$limit&offset=$offset&fields=$fields",'GET');
        $photos_data = array_merge($photos_data, $data["data"]);
    }

    return $photos_data;
}

You can change the value of $limit as you want, to get less/more data per call.

like image 177
F2000 Avatar answered Sep 17 '22 15:09

F2000