通过Facebook Graph API访问用户的朋友?

the*_*man 6 facebook oauth facebook-graph-api

有没有人通过Facebook Graph API成功访问用户朋友列表?

我编写了代码,通过Facebook的OAuth API对我网站上的用户进行身份验证.它的作品非常出色; 我可以访问公共信息,喜欢,兴趣,活动等.我通过以下URL格式访问这些数据点,我用"uid"替换有效的id(我使用uid代替"me",因为"我"不像宣传的那样工作):

https://graph.facebook.com/uid?access_token= ...
https://graph.facebook.com/uid/likes?access_token= ...
https://graph.facebook.com/uid/interests? access_token = ...
https://graph.facebook.com/uid/activities?access_token= ...

但是,访问朋友根本不起作用.网址,

https://graph.facebook.com/uid/friends?access_token= ...

返回以下错误:

{
   "error": {
      "type": "OAuthAccessTokenException",
      "message": "An access token is required to request this resource."
   }
}
Run Code Online (Sandbox Code Playgroud)

Graph API文档上的示例都可以正常工作,但在该页面上生成的访问令牌的格式与我的格式不同.我不知道为什么.我按照他们的指示去了一个发球台(让它为其他一切工作!).

朋友被认为是公开访问的信息,我已经仔细检查了我的Facebook帐户权限,所以我不认为这是问题.

Pas*_*ein 7

如果用户连接到您的应用程序,您可以检索他们的朋友,如下所示:

    $facebook = new Facebook(array(
                'appId' => 'xxxxxxxx',
                'secret' => 'xxxxxxx',
                'cookie' => true,
            ));

    // $session is only != null, when you have the session-cookie, that is set by facebook, after the user logs in
    $session = $facebook->getSession(); 

    // you dont get a list of friends, but a list, which contains other friendlists
    $friendsLists = $facebook->api('/me/friends');

    foreach ($friendsLists as $friends) {
      foreach ($friends as $friend) {
         // do something with the friend, but you only have id and name
         $id = $friend['id'];
         $name = $friend['name'];
      }
   }
Run Code Online (Sandbox Code Playgroud)

但您只能访问朋友的ID和姓名.


Sar*_*raz 0

您需要先获取访问令牌。看:

\n\n

Facebook Graph API \xe2\x80\x94 获取访问令牌

\n