2016-11-26 21 views
0

Wenn Benutzer öffnen Facebook Setting View, wie den aktuellen Anmeldestatus zu identifizieren. Und wenn es protokolliert wird, wie kann ich die weiteren Informationen der Benutzer abrufen. wie Geburtstag, Alter, Geschlecht, etc.Facebook Login Status Check Problem

Ich schrieb dieses Stück Code, der nicht funktioniert. Danke im Voraus.

- (void)viewDidLoad { 
[super viewDidLoad]; 

if ([FBSDKAccessToken currentAccessToken]) { 

    //Going to another ViewController, which include user's name, 
    //age, photo and so on. 
} else { 
    FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init]; 

    loginButton.center = self.view.center; 
    [self.view addSubview:loginButton]; 
} 


} 
+0

Ihr Zustand falsch zu holen ist. –

+0

Dann, wie es zu beheben? Danke im Voraus. – Nan

+0

welche facebook sdk-version verwenden sie –

Antwort

1
if ([FBSDKAccessToken currentAccessToken]) { 
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil] 
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { 
    if (!error) { 
    NSLog(@”fetched user:%@”, result); 
    } 
}]; 
} 

dieses seine Arbeits Versuchen.

https://developers.facebook.com/docs/ios/change-log-4.xhier Dokument enthält Informationen über SDK 4,0

Hier sind einige Graph API-Schlüssel zu erhalten.

"public_profile", 
"email", 
"user_friends" , 
"user_hometown", 
"user_work_history" , 
"user_birthday" , 
"user_education_history 
1

ist die umfassende und vollständige Codeinformationen des Benutzers

FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; 
[login 
logInWithReadPermissions: @[@"public_profile", @"user_friends", @"email"] 
fromViewController:self 
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { 
    if (error) { 
     DLog(@"Process error======%@",error.description); 
     indicators.hidden=YES; 
     [indicators stopAnimating]; 
    } else if (result.isCancelled) { 
     DLog(@"Cancelled"); 
     indicators.hidden=YES; 
     [indicators stopAnimating]; 
    } else { 

     if ([FBSDKAccessToken currentAccessToken]) { 



      [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, link, first_name, last_name, picture.type(large), email, birthday, bio ,location ,friends ,hometown , gender ,friendlists"}] 
       startWithCompletionHandler:^(
              FBSDKGraphRequestConnection *connection, id result, NSError *error) { 
        if (!error) 
        { 

         // NSLog(@"fetched user:%@", result); 

         // [self fetchingFacebookFriends]; 

         [defFacebookData setObject:[result objectForKey:@"email"] forKey:@"fbEmail"]; 

         [defFacebookData setObject:[result objectForKey:@"id"] forKey:@"fbID"]; 


         //PASS ID 
         getFbid = [result objectForKey:@"id"]; 
    NSLog(@"getFbid========>%@",getFbid); 

         //PASS FIRST NAME 
         getFbFirstName=[result objectForKey:@"first_name"]; 

    NSLog(@"first======>%@",getFbFirstName); 

         //PASS LAST NAME 
         getFBlastName=[result objectForKey:@"last_name"]; 
    NSLog(@"first======>%@",getFBlastName); 

         //PASS EMAIL 
         getFbemail=[result objectForKey:@"email"]; 
    NSLog(@"first======>%@",getFbemail); 

         //PASS PHONE 
         getfbGender=[result objectForKey:@"gender"]; 
    NSLog(@"first======>%@",getfbGender); 


         [defFacebookData setObject:[result objectForKey:@"name"] forKey:@"fbName"]; 

         // Image 
         FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] 
                initWithGraphPath:[NSString stringWithFormat:@"me/picture?type=large&redirect=false"] 
                parameters:nil 
                HTTPMethod:@"GET"]; 
         [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, 
                  id fbImageResult, 
                  NSError *error) { 

NSString *strURL = [NSString stringWithFormat:@"%@",[[fbImageResult objectForKey:@"data"] objectForKey:@"url"]]; 

    NSLog(@"strURL=====>%@",strURL); 

[defFacebookData setObject:strURL forKey:@"fbImage"]; 

          [defFacebookData synchronize]; 


          NSDictionary *fbdict=[NSDictionary dictionaryWithObjectsAndKeys:getFbid,@"id",getFbFirstName,@"first_name",getFBlastName,@"last_name",getFbemail,@"email",getfbGender,@"gender",strURL,@"fbImage", nil]; 

          NSLog(@"done=========>%@",fbdict); 

    UIStoryboard*storyboard=[AppDelegate storyBoardType]; 

    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults]; 


    BOOL fblogin =[defaults boolForKey:@"KeyEditProfile"]; 

     if (fblogin) 
      { 

       UIStoryboard*Storyboard=[AppDelegate storyBoardType]; 
       DashboardVC* tabbarController = (DashboardVC*)[Storyboard instantiateViewControllerWithIdentifier:@"DashboardVCId"]; 



       indicators.hidden=YES; 
       [indicators stopAnimating]; 

       [self.navigationController pushViewController:tabbarController animated:YES]; 

     } 

    else 
    { 
    EditFBVC *cpvc=(EditFBVC*)[storyboard instantiateViewControllerWithIdentifier:@"EditFBVCId"]; 
    NSLog(@"get fb id ===%@",getFbid); 


    cpvc.dictFacebookdict =fbdict; 

    cpvc.strFBlogin [email protected]"fbAllDataValue"; 

     indicators.hidden=YES; 
     [indicators stopAnimating]; 

    [self.navigationController pushViewController:cpvc animated:YES]; 

    } 
         }]; 
        } 
        else{ 

         DLog(@"error is %@", error.description); 
        } 
       }]; 
     } 
    } 
}];