Problem with fieldsMapping for Facebook login

Hi guys,

I have this code to login with Facebook.

NSDictionary *fieldsMapping = [NSDictionary dictionaryWithObjectsAndKeys:

                                   @"email",@"email",

                                   @"name",@"name",

                                   nil];

    BackendlessUser *user = [backendless.userService loginWithFacebookSDK:token fieldsMapping:fieldsMapping];

The problem is that fieldsMapping returns only the email but the name remains null.
Why?

Hi Francesco,

I scheduled a ticket to investigate this issue.

Regards,
Mark

Hi Francesco,

I just checked Facebook SDK login - it works fine for me.



- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    
    BOOL result = [[FBSDKApplicationDelegate sharedInstance] application:application
                                                                 openURL:url
                                                       sourceApplication:sourceApplication
                                                              annotation:annotation];
    
    FBSDKAccessToken *token = [FBSDKAccessToken currentAccessToken];
    
    NSLog(@"openURL: result = %@, url = %@\n userId: %@, token = %@, expirationDate = %@, permissions = %@", @(result), url, [token valueForKey:@"userID"], [token valueForKey:@"tokenString"], [token valueForKey:@"expirationDate"], [token valueForKey:@"permissions"]);
    
    NSDictionary *fieldsMapping = @{
                                    @"id" : @"facebookId",
                                    @"name" : @"name",
                                    @"birthday": @"birthday",
                                    @"first_name": @"fb_first_name",
                                    @"last_name" : @"fb_last_name",
                                    @"gender": @"gender",
                                    @"email": @"email"
                                    };    
    @try {
        BackendlessUser *user = [backendless.userService loginWithFacebookSDK:token fieldsMapping:fieldsMapping];
        NSLog(@"USER: %@", user);
        
        [backendless.userService logout];
        NSLog(@"LOGOUT");
    }
    @catch (Fault *fault) {
        NSLog(@"openURL: %@", fault);
    }
     return result;
}

http://support.backendless.com/public/attachments/9d75b411170660aea1aac8206ebab9df.png</img>

You can also try our sample - https://github.com/Backendless/iOS-Samples/tree/master/samples/objective-c/backendlessDemos/FacebookLogin, and compare with your project.

Regards,
Slava

I will try but your code is similar to my code :slight_smile:

I think you can’t use the “name” property from facebook. It would return null. Maybe your user’s “name” property is marked as a not null property?

Yes, “name” field is returned as null by server - now we are investigating this issue, it will be fixed asap. We will let you know about.

Please see this comment in another thread -http://support.backendless.com/t/loginwithfacebooksdk-results-in-fault-code-server-processing#comment-6688

Has it a sense?

Yes, as you can see, I already answered the same there too.

Yes, it has sense for me too. I tried with key “first_name” for my backend’s property “name”, and it still returns null

Francesco,

I checked with the dev team and was told a fix for this issue is going to be available in the upcoming release next week.

Regards,
Mark

I noticed same fix. But other issue. Without mapping Backendless put id of fb inside “email” field.

Maybe problem is here: https://github.com/Backendless/Android-SDK/blob/master/src/com/backendless/UserServiceAndroidExtra.java

Hi Francesco!
The issue has been fixed (mapping for “name” property).
Regards,
Kate.

Thank you Kate, I had found another solution that works but I will try this…