我正在尝试使用Graph API v2.0获取我的朋友姓名和ID,但数据返回空:
{
"data": [
]
}
当我使用v1.0时,以下请求一切正常:
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
NSArray* friends = [result objectForKey:@"data"];
NSLog(@"Found: %i friends", friends.count);
for (NSDictionary<FBGraphUser>* friend in friends) {
NSLog(@"I have a friend named %@ with id %@", friend.name, friend.id);
}
}];
但现在我找不到朋友了!
尽管Simon Cross的答案被接受并且是正确的,但我想我可以用一个例子(Android)来说明需要做什么。我会尽我所能保持它的概括性,只关注这个问题。就我个人而言,我将东西存储在一个数据库中,因此加载是平滑的,但这需要一个CursorAdapter和ContentProvider,这有点超出了这里的范围。
我自己来到这里,然后想,现在怎么了?!
问题
就像user3594351一样,我注意到朋友的数据是空白的。我是用FriendPickerFragment发现的。三个月前起作用的,现在不起作用了。甚至连Facebook的例子都被打破了。所以我的问题是“如何手工创建FriendPickerFragment?”?
什么不起作用
Simon Cross中的选项1不够强大,无法邀请朋友加入应用程序。Simon Cross也推荐了Requests对话框,但一次只允许五个请求。在任何给定的Facebook登录会话中,“请求”对话框也显示相同的朋友。没用。
什么有效(摘要)
选择2和一些艰苦的工作。你必须确保你符合Facebook的新规则:1)你是一个游戏2)你有一个画布应用(网络状态)3)你的应用已在Facebook注册。这都是在Facebook开发者网站的设置下完成的。
为了在我的应用程序中手动模拟好友选取器,我执行了以下操作:
详细信息
异步任务
我创建的FacebookFriend类
在图形API的v2.0中,调用
/me/friends
返回同时使用该应用程序的用户的朋友。此外,在v2.0中,必须向每个用户请求
user_friends
权限。user_friends
在默认情况下不再包含在每个登录中。每个用户都必须授予user_friends
权限,才能出现在对/me/friends
的响应中。有关详细信息,请参见the Facebook upgrade guide,或查看下面的摘要。如果要使用好友访问非应用程序列表,有两个选项:
If you want to let your people tag their friends在他们使用您的应用程序发布到Facebook的文章中,您可以使用
/me/taggable_friends
API。Use of this endpoint requires review by Facebook并且只应用于呈现朋友列表以便用户在帖子中标记他们的情况。If your App is a Game AND your Game supports Facebook Canvas,您可以使用
/me/invitable_friends
端点来呈现a custom invite dialog,然后将此API返回的令牌传递给the standard Requests Dialog.在其他情况下,应用程序将无法检索用户朋友的完整列表(仅限那些使用
user_friends
权限专门授权您的应用程序的朋友)。This has been confirmed by Facebook as 'by design'.对于希望允许人们邀请朋友使用应用程序的应用程序,您仍然可以使用Send Dialog on Web或新的Message Dialog on iOS和Android。
更新:Facebook在这里发布了一个关于这些更改的常见问题解答:https://developers.facebook.com/docs/apps/faq,它解释了开发人员可以使用的所有选项,以便邀请朋友等
Facebook现在已经修改了他们的政策。如果你的应用程序没有画布实现,或者你的应用程序不是游戏,那么无论如何你都无法获得整个好友列表。当然也有可标记的朋友,但那一个只用于标记。
您将能够拉仅授权应用程序的朋友列表。
使用GraphAPI1.0的应用程序将工作到2015年4月30日,之后将被弃用。
有关详细信息,请参见以下内容:
User Friends
Facebook Application Development FAQ
相关问题 更多 >
编程相关推荐