1

我已经在我的应用程序中集成了 facebook 登录。但我无法获取用户数据,即它没有进入 Appdelegate.m 中的用户详细信息循环

- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
    NSArray *permissions = [[NSArray alloc] initWithObjects:
                            @"email",
                            @"user_likes",
                            nil];
    return [FBSession openActiveSessionWithReadPermissions:permissions
                                              allowLoginUI:allowLoginUI
                                         completionHandler:^(FBSession *session,
                                                             FBSessionState state,
                                                             NSError *error) {
                                             [self sessionStateChanged:session
                                                                 state:state
                                                                 error:error];
                                         }];





}


- (void)sessionStateChanged:(FBSession *)session
                      state:(FBSessionState) state
                      error:(NSError *)error
{
    switch (state) {
        case FBSessionStateOpen:
                     if (!error) {
                // We have a valid session
                NSLog(@"User session found");


                         [[FBRequest requestForMe] startWithCompletionHandler:
                          ^(FBRequestConnection *connection,
                            NSDictionary<FBGraphUser> *user,
                            NSError *error) {
                                  if (!error) {

                                  NSLog(@"%@",user);



                              }}];
                           break;
        case FBSessionStateClosed:
        case FBSessionStateClosedLoginFailed:
           [[FBSession activeSession] closeAndClearTokenInformation];

            break;
        default:
            break;
    }
 if (error) {
        UIAlertView *alertView = [[UIAlertView alloc]
                                  initWithTitle:@"Error"
                                  message:error.localizedDescription
                                  delegate:nil
                                  cancelButtonTitle:@"OK"
                                  otherButtonTitles:nil];
        [alertView show];
    }

    }
}

但是我没有找到要打印的用户 NSLog(@"%@",user) 的 NSLog,即使会话已打开 bcoz NSLog(@"User session found") 已打印 Y 是这样吗?

4

1 回答 1

0

我有同样的问题,我在一个小时后登录后回来后无法进入该块,我发现我正在返回 mysession 类而不是 mysession 的实例。这可能会解决您的问题:

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {

    return [mysession handleOpenURL:url];
}
于 2013-02-19T13:44:34.010 回答