如何使用PHP SDK v5检索Facebook好友?

时间:2016-12-30 02:36:39

标签: facebook api facebook-graph-api facebook-php-sdk

我试图通过PHP SDK v5检索我的Facebook朋友。

// $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>';

结果如下:

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
        (
        )

)

如何获得 total_count 值(560)?我错过了什么吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

根据文档,您的Facebook\GraphNodes\GraphEdge has a getMetaData function可以访问该metaData:protected部分。