如何使用PHP阅读facebook好友列表?

如何使用PHP阅读facebook好友列表?,php,facebook,facebook-graph-api,Php,Facebook,Facebook Graph Api,我从developers.Facebook.com创建了Facebook应用程序。我有应用程序ID和应用程序机密 我已授予以下权限: read_stream, manage_friendlists, user_friends 我使用以下代码读取我的facebook id和姓名: $userdetails = file_get_contents( "https://graph.facebook.com/v2.0/me?fields=id,name&access_token=".$acce

我从developers.Facebook.com创建了Facebook应用程序。我有应用程序ID和应用程序机密

我已授予以下权限:

read_stream, manage_friendlists, user_friends
我使用以下代码读取我的facebook id和姓名:

$userdetails = file_get_contents(
"https://graph.facebook.com/v2.0/me?fields=id,name&access_token=".$access_token);
我得到了JSON格式的id和名称。
{“id”:“my_id”,“name”:“Sathish Kumar”}

我使用以下代码获取friendslist


$userdetails=文件获取内容(“https://graph.facebook.com/v2.0/me?fields=id、姓名、好友和访问令牌=“.$access\u-token”)

但是,我收到了警告信息

Warning: file_get_contents(https://graph.facebook.com/v2.0/me?fields=id,name,friends&access_token=my_access_token) 

[function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error

如何使用facebook api获取好友列表?

正确的端点应该是
/me/friends
,您需要为此进行另一个api调用。我强烈建议使用CURL,而不是
file\u get\u contents


请记住,您将只获得已经使用该应用程序的朋友,请参阅更改日志:

此代码对我来说很好。检查您的访问令牌是否有效

$userdetails = file_get_contents("https://graph.facebook.com/v2.0/me?fields=id,name&access_token=".$access_token);

graph api有一些方法,请尝试它们。我修复了第二个代码,您发布了两次相同的代码。请查看我的答案,100%正确。嗨,Luschn,我在字段中添加了“朋友”,请检查此字段=id、姓名、朋友。我的问题是获取好友列表。嘿,谢谢你的回复。以上代码对我有效,但我需要获得我的好友列表。如何获取我的好友列表?$userdetails=file_get_contents(“);use friends字段返回数组输出中的所有好友列表:-{“id”:“登录用户的id”,“name”:“登录用户名”,“friends”:{“data”:[],“summary”:{“total_count”:0}我尝试了相同的代码。但我收到了警告消息。我在问题中已经提到。“无法打开流。”“这是因为套接字的默认超时为60秒。在慢速网络连接中,最常见的错误是使用php open标记后顶部的以下代码。此代码将套接字的默认超时从1分钟设置为15分钟。ini_set('default_socket_timeout',900);并将php文件执行时间更改为无限ini_集('max_execution_time',0);这会解决你的问题