gpt4 book ai didi

facebook - 通过 Facebook Graph API 访问用户的好友?

转载 作者:行者123 更新时间:2023-11-30 05:21:53 27 4
gpt4 key购买 nike

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

我编写了代码,通过 Facebook 的 OAuth API 对我网站上的用户进行身份验证。它工作得很好;我可以访问公共(public)信息、喜好、兴趣、事件等。我通过以下 URL 格式访问这些数据点,其中我用有效 ID 替换“uid”(我使用 uid 代替“我”,因为“我”不像宣传的那样工作):

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."
}
}

Graph API docs 上的示例一切正常,但该页面上生成的访问 token 的格式与我的不同。我不确定为什么。我已经按照他们的指示进行了发球(并让它适用于其他一切!)。

friend 都算publicly accessible information ,并且我仔细检查了我的 Facebook 帐户权限,所以我认为这不是问题所在。

最佳答案

如果用户连接到您的应用程序,您可以像这样检索他们的好友:

    $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'];
}
}

但是您只能访问好友的 ID 和姓名。

关于facebook - 通过 Facebook Graph API 访问用户的好友?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3240561/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com