Facebook Graph API:解析输出
我试图通过此调用使用 FB Graph API 获取朋友的姓名:
$friends = file_get_contents('https://graph.facebook.com/me/friendsaccess_token='.$session["access_token"]);
echo "Friends : $friends\n";
这给了我一个以下形式的列表:
{"data":[{"name":"ABC XYZ","id":"12212839"},{"name":"PQR GHI","id":"5004678"}]}
我希望能够仅将名称存储在数组中。如何使用 $friends 获取姓名?像 $friends['name'] 这样的东西似乎不起作用。
请帮忙。 谢谢。
I am trying to get the names of my friends using FB Graph API with this call :
$friends = file_get_contents('https://graph.facebook.com/me/friendsaccess_token='.$session["access_token"]);
echo "Friends : $friends\n";
This gives me a list of the form :
{"data":[{"name":"ABC XYZ","id":"12212839"},{"name":"PQR GHI","id":"5004678"}]}
I want to be able to store only the NAMES in an array. How do I use $friends to get the names ? Something like $friends['name'] doesn't seem to work.
Please help.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
返回的是一个json对象,需要对其进行解码。尽管我强烈建议您使用 SDK,例如 http://github.com/facebook/php-sdk /
如果这不起作用,请尝试:
The return is a json object, you need to decode it. Although I strongly urge you to use an SDK such as http://github.com/facebook/php-sdk/
If this doesn't work try:
这是我为获取帖子信息所做的事情。虽然很粗糙,但它有效。请注意,点赞评论和反应的分享在 JSON 对象中更深一层
Here is what I did to get the posts information.. crude but it works. Note that the shares likes comments and reactions are one level deeper in the JSON object