使用facebook api来获取朋友列表 [英] Getting friends list using facebook api's

查看:103
本文介绍了使用facebook api来获取朋友列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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!'));

ie。使用url https://graph.facebook.com/<user id到这里> / feed

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?

我需要使用的URL是 https: /graph.facebook.com/me/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!'));



<
$ b

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?

推荐答案

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

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

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






但是,如果您没有有效的会话(或需要离线检索),则需要 offline_access 权限,您的代码也可以正常工作。

更新:

自从 offline_access 权限,您需要长寿命 access_token


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.

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

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())"
));

这篇关于使用facebook api来获取朋友列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆