我无法获得 user_birthday 和 user_hometown 的权限。 我之前尝试使用此代码,但它只询问公开个人资料并忽略其他人。
[FBSession openActiveSessionWithReadPermissions:@[@"public_profile",@"user_birthday",@"user_hometown"]
allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if (error) {
NBAppDelegate* appDel = (NBAppDelegate*)`[UIApplication sharedApplication].delegate;
[appDel sessionStateChanged:session state:status error:error];
}
if ([session isOpen]) {
[self loginWithFBToken:session name:sender];
}
}];
然后有人建议在获取公开个人资料后要求获得额外的权限,所以我甚至尝试了这一点。
以下是
的代码- (void)loadFbDetails
{
NSArray *permissionsNeeded = @[@"user_hometown", @"user_birthday"];
// Request the permissions the user currently has
[FBRequestConnection startWithGraphPath:@"/me/permissions"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error){
// These are the current permissions the user has:
NSDictionary *currentPermissions= [(NSArray *)[result data] objectAtIndex:0];
// We will store here the missing permissions that we will have to request
NSMutableArray *requestPermissions = [[NSMutableArray alloc] initWithArray:@[]];
// Check if all the permissions we need are present in the user's current permissions
// If they are not present add them to the permissions to be requested
for (NSString *permission in permissionsNeeded){
if (![currentPermissions objectForKey:permission]){
[requestPermissions addObject:permission];
}
}
// If we have permissions to request
if ([requestPermissions count] > 0){
// Ask for the missing permissions
[FBSession.activeSession
requestNewReadPermissions:requestPermissions
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
// Permission granted
NSLog(@"new permissions %@", [FBSession.activeSession permissions]);
// We can request the user information
[self makeRequestForUserData];
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
}
}];
} else {
// Permissions are present
// We can request the user information
[self makeRequestForUserData];
}
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
}
}];
}
-(void)makeRequestForUserData
{
[FBRequestConnection startWithGraphPath:@"me?fields=birthday,hometown"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Sucess! Include your code to handle the results here
NSLog(@"user events: %@", result);
} else {
NSLog(@"error: %@" , error);
}
}];
}
所有这一切都是递归地在我的ios应用程序和fb本机应用程序之间进行,只返回权限数组中的public_profile。
看起来我错过了什么?
答案 0 :(得分:6)
如果你正在使用该应用的管理员用户,它应该可以使用。一旦您想与其他用户一起使用扩展权限,您必须首先通过Facebook审核您的应用。
请在此处查看我的回答:facebook extended permission
答案 1 :(得分:1)
默认情况下,Facebook不允许应用访问该信息。您必须向Facebook请求许可才能使用该信息。为Facebook员工添加视频和说明,了解您如何使用生日和家乡英特尔。