0

在我的应用程序中,当我检索用户位置时,它返回一个 Null 值,并且生日也返回 Null 值,代码如下,

 - (void)populateUserDetails {
if (FBSession.activeSession.isOpen) {
    [[FBRequest requestForMe] startWithCompletionHandler:
     ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error)           {
         if (!error) {
             self.userNameLabel.text = user.name;
             self.userProfileImage.profileID = [user objectForKey:@"id"];
             self.userbirthday.text=user.birthday;
             self.userloc=[[user objectForKey:@"location"]  objectForKey:@"name"];

         }
     }];
   }
 }

代码有什么问题?请帮我解决这个问题?

4

1 回答 1

2

对于生日和位置,您需要获得此类许可。所以你需要像这样请求权限:Facebook SDK Documentation

- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
    NSArray *permissions = [[NSArray alloc] initWithObjects:
                            @"user_location", // you need to have this permission
                            @"user_birthday", // to be approved
                            @"user_likes",
                            nil];
    return [FBSession openActiveSessionWithReadPermissions:permissions
                                              allowLoginUI:allowLoginUI
                                         completionHandler:^(FBSession *session,
                                                         FBSessionState state,
                                                         NSError *error) {
                                         [self sessionStateChanged:session
                                                             state:state
                                                             error:error];
                                     }];
}

然后使用 FBRequest 检索生日和位置。您可以访问用户名,因为它不需要特殊权限。

于 2013-02-19T10:26:47.170 回答