PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, February 27, 2022

[FIXED] How to use paging next in the new Facebook PHP SDK 4

 February 27, 2022     facebook, facebook-graph-api, facebook-php-sdk, php     No comments   

Issue

I am using the new Facebook PHP SDK. I trying to get the name of all the pages liked by the user. But it is only returning me 25 of them. As far as I know if I have to get all of them then I will have to use the "next link" in the "paging" returned by the "graphObject".

But I have no idea how to use it. And if I am wrong then can you point out how can I do it?


Solution

I'm doing this in php in order to get all the likes:

public function getLikes () {

    $likes = array();

    // Custom method! Get the session however you like
    $session = $this->getSession();

    $request = new FacebookRequest(
        $session,
        'GET',
        '/me/likes'
    );

    do {
        $response = $request->execute();
        $graphObject = $response->getGraphObject();
        $some_likes = $graphObject->getProperty('data')->asArray();
        $likes = array_merge($likes, $some_likes);
    } while ($request = $response->getRequestForNextPage());

    return $likes;
}

As you can see, the getRequestForNextPage() method is the key.



Answered By - Diego Castaño Chillarón
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing