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

Sunday, February 27, 2022

[FIXED] Parse Facebook graphEdge as array php sdk

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

Issue

I am trying to get a users friends count from Facebook php sdk v5. How can I parse the response from as a php array or how can I retrieve the total friends count? ->asArray() (that i use with getGraphUser) does not work on getGraphEdge it seems. I am unsure how to access or convert it.

try {
      // Returns a `Facebook\FacebookResponse` object
      $response = $cfb->get('/me/friends?fields=id', $_SESSION['fb_token']);
        $friends = $response->getGraphEdge();
    } catch(Facebook\Exceptions\FacebookResponseException $e) {
      echo 'Graph returned an error: ' . $e->getMessage();
      //exit;
    } catch(Facebook\Exceptions\FacebookSDKException $e) {
      echo 'Facebook SDK returned an error: ' . $e->getMessage();
      //exit;
    }

Facebook\GraphNodes\GraphEdge Object
(
    [request:protected] => Facebook\FacebookRequest Object
        (
            [app:protected] => Facebook\FacebookApp Object
                (
                    [id:protected] => ****
                    [secret:protected] => ****
                )

            [accessToken:protected] => *****
            [method:protected] => GET
            [endpoint:protected] => /me/friends?fields=id
            [headers:protected] => Array
                (
                    [Content-Type] => application/x-www-form-urlencoded
                )

            [params:protected] => Array
                (
                )

            [files:protected] => Array
                (
                )

            [eTag:protected] => 
            [graphVersion:protected] => v2.2
        )

    [metaData:protected] => Array
        (
            [summary] => Array
                (
                    [total_count] => 468
                )

        )

    [parentEdgeEndpoint:protected] => 
    [subclassName:protected] => 
    [items:protected] => Array
        (
        )

)

Thanks in advance!


Solution

Had to use the getTotalCount() method.

https://developers.facebook.com/docs/php/GraphEdge/5.0.0#get-total-count



Answered By - Clint C.
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

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