我目前正试图通过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和名称的数组。任何帮助将不胜感激!
答案 0 :(得分:1)
您可以使用all()
方法访问GraphNode对象的protected items属性(它是Collection
类的继承方法,GraphNode扩展)。
这只会将项目作为数组返回。
我希望这会有所帮助!