iOS Facebook SDK 3.1检索返回null的朋友生日 [英] iOS Facebook SDK 3.1 Retrieve friend birthday returning null
问题描述
我正在尝试检索 facebook 朋友的生日数据,但它返回 null.我正在使用此代码:
I'm trying to retrieve birthday data of facebook friends, but it's returning null. I'm using this code:
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 %@ - birthday %@", friend.name, friend.birthday);
}
}];
朋友姓名没问题,但朋友生日或不是基本朋友数据之一的所有数据都返回 null.请注意,我已经在 facebook.com 应用页面和 openSession 方法(登录)中添加了 user_birthday 和 friends_birthday 权限:
Friend name is ok, but friend birthday or all data that is not one of the basics friends data is returning null. Note i'm already added user_birthday and friends_birthday permissions in facebook.com app page and in openSession method (login):
- (void)openSession
{
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"user_birthday",
@"friends_birthday",
nil];
[FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:YES
completionHandler:
^(FBSession *session,
FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
}
这里需要一些帮助,我已经尝试了所有方法.
Needing some help here, i've already tried everything.
推荐答案
我也有同样的问题,我是这样解决的.
I have the same problem and i solve this way.
首先,请确保您拥有正确的权限.
First of all, be sure that you have the correct permissions.
NSArray *permissions = @[@"user_birthday", @"friends_hometown",
@"friends_birthday", @"friends_location"];
[FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:YES completionHandler: .....
那么,不要使用 requestForMyFriends.我尝试了几种方法(更改 FBRequest 和这类事情
Then, DO NOT USE requestForMyFriends. I try in several ways ( changing the FBRequest and this kind of things
检查权限并确保它是您需要的权限.
Check the permissions and be sure that it was the permissions you need.
NSLog(@"permissions::%@",FBSession.activeSession.permissions);
现在以这种方式生成 FBRequest.
Now generate the FBRequest this way.
FBRequest *friendRequest = [FBRequest requestForGraphPath:@"me/friends?fields=name,picture,birthday,location"];
[ friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSArray *data = [result objectForKey:@"data"];
for (FBGraphObject<FBGraphUser> *friend in data) {
NSLog(@"%@:%@", [friend name],[friend birthday]);
}}];
我终于得到了这个数据.希望对你有帮助
I finally get this data. I hope it helps you
这篇关于iOS Facebook SDK 3.1检索返回null的朋友生日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!