【问题标题】:Can't get permissions for user_birthday and user_hometown in facebook-ios-sdk无法在 facebook-ios-sdk 中获取 user_birthday 和 user_hometown 的权限
【发布时间】:2014-07-21 10:14:02
【问题描述】:

我无法获得 user_birthdayuser_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


【解决方案1】:

如果您使用的是应用的管理员用户,它应该可以工作。一旦您想对其他用户使用扩展权限,您必须先让 Facebook 审核您的应用。

在这里查看我的答案:facebook extended permission

【讨论】:

    【解决方案2】:

    默认情况下,Facebook 不允许应用访问该信息。您必须获得 Facebook 的许可才能使用该信息。添加视频和说明,让 Facebook 员工查看您如何使用生日和家乡信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-04
      • 1970-01-01
      相关资源
      最近更新 更多