使用 facebook api 获取好友列表
我有以下命令,该命令允许我在登录的用户 facebook 墙上发布消息:
$facebook->api("/$uid/feed", "POST", array('message' => 'Hello! I\'m using the FB Graph API!'));
即使用 url https://graph.facebook.com/
但是我需要输入什么命令才能获取已登录用户好友的列表呢?
我需要使用的网址是 https://graph.facebook.com/me/friends
,但我不确定如何编辑以下命令来获取好友列表:
$facebook->api("/$uid/feed", "POST", array('message' => 'Hello! I\'m using the FB Graph API!'));
我应该做什么像这样的事情(这是一个完整的猜测)
$facebook->api("/$uid/friends", "GET", array('access_token' => 'token value goes here'));
或者我应该做其他事情来获取朋友列表?
I have the following command which will allow me to post a message on the logged in users facebook wall:
$facebook->api("/$uid/feed", "POST", array('message' => 'Hello! I\'m using the FB Graph API!'));
i.e. using the url https://graph.facebook.com/<user id goes here>/feed
But what command do I need to enter to get a list of the logged in users friends?
The url I need to use is https://graph.facebook.com/me/friends
, but I am not sure how to edit the below command to get the friends list:
$facebook->api("/$uid/feed", "POST", array('message' => 'Hello! I\'m using the FB Graph API!'));
am I supposed to do something like this (which is a complete guess)
$facebook->api("/$uid/friends", "GET", array('access_token' => 'token value goes here'));
Or am I supposed to do something else to get the friends list?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您有有效的会话,那么这应该检索当前用户的朋友:
但是如果您没有有效的会话(或需要离线检索此会话),则需要offline_access
权限,并且您的代码也将起作用。更新:
由于
offline_access
权限被废弃,您需要 长期存在的access_token
。请注意,您也可以使用此 FQL 查询获取好友列表:
If you have a valid session, then this should retrieve the current user's friends:
But if you don't have a valid session (or need to retrieve this offline) you need theoffline_access
permission and your code will also work.UPDATE:
Since the deprication of the
offline_access
permission, you need a long-livedaccess_token
.Please note that you can get the friends list with this FQL query too:
SO 上的这篇文章可能会提供您正在寻找的答案。您将需要获取 Friends 对象,然后对其执行 foreach 循环以打印结果(如帖子中所述)。阅读使用最新 API 获取 Facebook 好友列表
This post on SO may provide the answer you are looking for. You will need to get the friends object then do a foreach loop over it to print the results (as described in the post). Read Getting list of Facebook friends with latest API