-1

Hi I just use this api for getting user details but I can't get user name please help me

[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:[NSDictionary dictionaryWithObject:@"id,first_name,last_name,gender,email,picture.type(large),groups" forKey:@"fields"]]
 startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {

     if (error==nil) {
     }else {

         NSLog(@"facebook erro : %@ ",error);
     }
 }];
Arasuvel
  • 2,971
  • 1
  • 25
  • 40

2 Answers2

0

You need to ask permissions to access data which is not public.

Check the blog here, it mentions how to request permission for private data.

This is a snippet from the above blog

let loginManager = FBSDKLoginManager()
let permissions = ["public_profile", "email","username"] //not sure username is to be used or user_name.
let handler = loginManager.logInWithReadPermissions(permissions, fromViewController: self, handler: handler)

After the user grants access to his private data. You will be able to retrieve the data.

Mukul More
  • 554
  • 2
  • 5
  • 18
  • FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; login.loginBehavior = FBSDKLoginBehaviorWeb; [login logInWithReadPermissions: @[@"public_profile", @"email",@"user_likes",@"user_groups",@"username",@"user_managed_groups"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { if ([result.declinedPermissions containsObject:@"publish_actions"]) { NSLog(@"declained permissions"); } else { } }]; – Saiprabhakar Mar 08 '18 at 05:43
  • if I use about code I got issue that is "invalid Scope: username" – Saiprabhakar Mar 08 '18 at 05:49
  • Are you getting user id ? – Mukul More Mar 08 '18 at 06:40
  • No I use with FBSDKAccessToken. if ([FBSDKAccessToken currentAccessToken]) { [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:[NSDictionary dictionaryWithObject:@"id,first_name,last_name,gender,email,picture.type(large),groups" forKey:@"fields"]] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { if (error==nil) { }else { NSLog(@"facebook erro : %@ ",error); } }]; } – Saiprabhakar Mar 08 '18 at 07:06
0

Facebook iOS sdk get user name and email in swift 3 -

FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, email"]).start(completionHandler: { (connection, result, error) -> Void in
        if (error == nil){
            let fbDetails = result as! NSDictionary
            print(fbDetails)
        }else{
            print(error?.localizedDescription ?? "Not found")
        }
    })
Rashed
  • 2,349
  • 11
  • 26