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

Thursday, January 6, 2022

[FIXED] How to retrieve Facebook friends count with PHP SDK v5?

 January 06, 2022     api, facebook, facebook-graph-api, facebook-php-sdk     No comments   

Issue

I'm trying to retrieve my Facebook's friends count with the PHP SDK v5.

// $access_token is already being successfully filled, using this example:
// https://developers.facebook.com/docs/php/howto/example_facebook_login

$response = $fb->get('/me/friends', $access_token);

# obtain user object
$user = $response->getGraphEdge();

# test
echo '<pre>';
print_r($user);
echo '</pre>';

This is the result:

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

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

            [params:protected] => Array
                (
                )

            [files:protected] => Array
                (
                )

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

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

        )

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

)

How do I get the total_count value (560)? Am I missing something?

Thanks!


Solution

Per the docs, your Facebook\GraphNodes\GraphEdge has a getMetaData function to access that metaData:protected section.



Answered By - ceejayoz
  • 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