2012-12-15 20 views
1

我已經整合Facebook登錄我app.But林無法獲取用戶數據,即不能進入用戶的詳細信息環路 在Appdelegate.m從Facebook登錄xcode獲取用戶數據?

- (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 NSLog的的(@」 %@「,用戶)即使打開會話也會打印bcoz NSLog(@」找到用戶會話「)打印 是這樣嗎?

+0

您能告訴我們您是如何開啓會議的嗎? (大概類似'[FBSession openActiveSessionWithReadPermissions:allowLoginUI:completionHandler:]' –

+0

我編輯了我的代碼,可以看看並糾正我的錯誤 – Sindhia

+0

如何在沒有記錄任何內容的情況下知道會話已打開? –

回答

0

我遇到了同樣的問題,一個小時後我登錄進去後無法進入該塊,我發現我正在返回mysession類而不是mysession的實例。這可能會解決您的問題:

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

    return [mysession handleOpenURL:url]; 
}