0

我跟着一個'在線指南,但我不知道如何獲得用戶的用戶名,如Facebook。 登錄和會話正常工作。 但我不能只取當前用戶的值。 這是工作的代碼獲取信息用戶Facebook的SDK iOS

if (!appDelegate.session.isOpen) { 
    // create a fresh session object 
    appDelegate.session = [[FBSession alloc] init]; 

    // if we don't have a cached token, a call to open here would cause UX for login to 
    // occur; we don't want that to happen unless the user clicks the login button, and so 
    // we check here to make sure we have a token before calling open 
    if (appDelegate.session.state == FBSessionStateCreatedTokenLoaded) { 
     // even though we had a cached token, we need to login to make the session usable 
     [appDelegate.session openWithCompletionHandler:^(FBSession *session, 
                 FBSessionState status, 
                 NSError *error) { 



      NSLog(@"SESSION FACEBOOK OK"); 

      // how i get username ? 

在此先感謝

回答

1

瞭解如何使用Facebook Graph API

要請求user info

[FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) { 
    if (!error) { 
     // Success! Include your code to handle the results here 
     NSLog(@"user info: %@", result); 
    } else { 
     // An error occurred, we need to handle the error 
     // See: https://developers.facebook.com/docs/ios/errors 
    } 
}]; 
+0

我都試過,但還是會話是活動的代碼不進入,如果... –

+0

請從鏈接一步一步跟着代碼,你會懂嗎。花點時間試試看;如果您發現任何困難,請告訴我 –

相關問題