简体   繁体   中英

How do I obtain user fields from Facebook login

I'm busy implementing Facebook login for my django site. I'm not sure if I'm on the right track or way off the ball at the moment. I have implemented the full code as seen in the FB doc example https://developers.facebook.com/docs/facebook-login/web . Basically inserted script on the template. I have the button and once logging in I have the "Welcome fetching your information" "successful login for Joshua Raphael" in my console.log.

How do I now obtain the required email, username and profile pic? Is it a part of the response object? Also if I have email login, is it possible to obtain the response email and check my current database to see if the user is already registered?

Prefer not to use pre-made django apps but if you highly recommend one I may try it.Thanks

I assume you are doing this:

FB.login(function(response) {
if (response.authResponse) {
 console.log('Welcome!  Fetching your information.... ');
 FB.api('/me', function(response) {
   console.log('Good to see you, ' + response.name + '.');
 });
} else {
 console.log('User cancelled login or did not fully authorize.');
}

});

you can console.log the response and see what all it contains, you will get the email, username and profilepic in it, also you can specify the fields if it is not there like this:

FB.api('/me', {fields: 'last_name'}, function(response) {
   console.log(response);
});

more here

also make sure you have added email in the scope in login method. like this:

FB.login(function(response) {
   // handle the response
}, {scope: 'public_profile,email'});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM