我想在我的应用程序上获得用户和朋友的生日。
我试图检索facebook朋友的生日数据,但它返回null。我使用以下代码:
- (IBAction)login_click:(id)sender
{
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"email", @"user_friends",@"user_birthday",@"friends_birthday"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
if (error)
{
// Process error
NSLog(@"error is :%@",error);
}
else if (result.isCancelled)
{
// Handle cancellations
NSLog(@"error is :%@",error);
}
else
{
NSLog(@"Login successfull");
[self fetchUserInfo];
}
}
}];
}
-(void)fetchUserInfo
{
if ([FBSDKAccessToken currentAccessToken])
{
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id,name,link,first_name, last_name, picture, email, birthday, bio ,location ,friends ,hometown , friendlists"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error)
{
NSLog(@"result : %@",result);
NSLog(@"user birthday : %@",[result valueForKey:@"birthday"]);
NSLog(@"friends Birthday : %@",[result valueForKey:@"friends_birthday"]);
}
}];
}
}
但是用户的生日和朋友的生日返回NULL
随着图API 2.0版本的引入,friends_*
已被弃用。所以你不能再得到它们了。此外,/me/friends
将只返回那些也在使用您的应用程序的朋友。
同时,您尝试请求一些您没有收集权限的字段,这将无法正常工作。
看- https://developers.facebook.com/docs/apps/changelog v2_0