satheesh kumar
satheesh kumar

Reputation: 113

iOS FacebookSDK4.0 get user information

Code:

FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];

    [login logInWithReadPermissions: @[@"public_profile"]
     handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
         if (error) {
             NSLog(@"Process error");
         } else if (result.isCancelled) {
             NSLog(@"Cancelled");
         } else {
             NSLog(@"result:%@", result);

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


                      }
                  }];
             }
             NSLog(@"Logged in");
         }
     }];

I used Facebook sdk4 for login integration.It is working fine and authentication also get success.How do i get information such as first name, last name, profile url, birthdate etc.The FBSDKGrpahRequest handler returns id and name alone.How do i get other details?

Upvotes: 2

Views: 137

Answers (1)

Larry Pickles
Larry Pickles

Reputation: 4646

You need to set the parameters value in the call to the specific data you want to retrieve. For example:

 parameters:@{@"fields": @"id, name"}

This as well:

FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name"}];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {}];

In your code above, you have parameters set to "nil", so to make your code work like you want it to, do this:

FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];

[login logInWithReadPermissions: @[@"public_profile"]
 handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
     if (error) {
         NSLog(@"Process error");
     } else if (result.isCancelled) {
         NSLog(@"Cancelled");
     } else {
         NSLog(@"result:%@", result);

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


                  }
              }];
         }
         NSLog(@"Logged in");
     }
 }];

For your purposes, you want to request parameters like so:

parameters:@{@"fields": @"id, name, first_name, last_name, birthday, picture"}

Upvotes: 3

Related Questions