【发布时间】:2014-07-21 10:14:02
【问题描述】:
我无法获得 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。
看起来我错过了什么?
【问题讨论】:
-
如果您使用 FB 应用程序的管理员用户,这是否有效?
-
我是开发者(不是管理员?),我用过那个账号吗?你认为这是一个问题吗?并且没有任何错误的代码?
标签: ios facebook facebook-graph-api facebook-ios-sdk