使用 PHP 在 Facebook 上提取好友列表


Extracting List of Friends on Facebook with PHP

我目前正在尝试通过 PHP 通过 FB SDK 提取我的朋友列表。这是返回给我的图形对象。

Facebook'GraphNodes'GraphNode Object ( [items:protected] => Array ( [gender] => female [friends] => Facebook'GraphNodes'GraphEdge Object ( [request:protected] => Facebook'FacebookRequest Object ( [app:protected] => Facebook'FacebookApp Object ( [id:protected] => OMITTED [secret:protected] => OMITTED ) [accessToken:protected] => OMITTED [method:protected] => GET [endpoint:protected] => me/?fields=about%2Cbio%2Cbirthday%2Cgender%2Chometown%2Crelationship_status%2Cfriends [headers:protected] => Array ( [Content-Type] => application/x-www-form-urlencoded ) [params:protected] => Array ( ) [files:protected] => Array ( ) [eTag:protected] => [graphVersion:protected] => v2.5 ) [metaData:protected] => Array ( [summary] => Array ( [total_count] => 1001 ) ) [parentEdgeEndpoint:protected] => /10206890247526057/friends [subclassName:protected] => [items:protected] => Array ( ) ) [id] => 10206890247526057 ) ) 

我正在尝试提取此对象中的数据:

[friends] => Facebook'GraphNodes'GraphEdge Object

并尝试通过PHP执行此操作。我使用以下代码得到上面的结果:

$req2 = $fb->get("me/fields=about,bio,birthday,gender,hometown,relationship_status,friends");
$all = $req2->getGraphObject();
print_r($all);

无法找到我试图提取的内容的骨头,那就是朋友 ID 和姓名的数组。任何帮助将不胜感激!

您可以使用

all() 方法访问 GraphNode 对象的受保护项属性(它是从 GraphNode 扩展的Collection类继承的方法)。

这将简单地将项目作为数组返回。

我希望这会有所帮助!