使用 facebook api 获取好友列表

发布于 2024-11-04 03:24:00 字数 710 浏览 1 评论 0原文

我有以下命令,该命令允许我在登录的用户 facebook 墙上发布消息:

$facebook->api("/$uid/feed", "POST",  array('message' => 'Hello! I\'m using the FB Graph API!'));

即使用 url https://graph.facebook.com//feed

但是我需要输入什么命令才能获取已登录用户好友的列表呢?

我需要使用的网址是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉生梦死 2024-11-11 03:24:00

如果您有有效的会话,那么这应该检索当前用户的朋友:

$friends = $facebook->api("/me/friends")

但是如果您没有有效的会话(或需要离线检索此会话),则需要 offline_access 权限,并且您的代码也将起作用。
更新:
由于 offline_access 权限被废弃,您需要 长期存在的 access_token


请注意,您也可以使用此 FQL 查询获取好友列表:

$friends = $facebook->api(array(
    "method"    => "fql.query",
    "query"     => "SELECT uid,name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())"
));

If you have a valid session, then this should retrieve the current user's friends:

$friends = $facebook->api("/me/friends")

But if you don't have a valid session (or need to retrieve this offline) you need the offline_access permission and your code will also work.
UPDATE:
Since the deprication of the offline_access permission, you need a long-lived access_token.


Please note that you can get the friends list with this FQL query too:

$friends = $facebook->api(array(
    "method"    => "fql.query",
    "query"     => "SELECT uid,name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())"
));
固执像三岁 2024-11-11 03:24:00

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文