问题
I'm using Satellizer to do a Facebook login, it works great except that Facebook is not returning all the users info. I'm only getting a name and ID but no email when I inculde in my scope email and public_profile.
Here is my FB config on the client side, and as you can see, I'm asking for email and public_profile:
facebook: {
clientId: 'xxxxxxx',
url: '/api/public/authentication/facebook',
authorizationEndpoint: 'https://www.facebook.com/v2.3/dialog/oauth',
redirectUri: window.location.protocol + '//' + window.location.host + '/', // window.location.origin || window.location.protocol + '//' + window.location.host + '/'
scope: 'email,public_profile',
scopeDelimiter: ',',
requiredUrlParams: ['display', 'scope'],
display: 'popup',
type: '2.0',
popupOptions: { width: 481, height: 269 }
},
On the server, this:
request.get( { url: graphApiUrl, qs: accessToken, json: true }, function( err, response, profile ) { ....
Only gives for the profile the id and name like so:
profile = Object {name: Denis, id: xxx}
No idea what I'm doing wrong and why I'm not getting the email, the avatar...
Thanks.
回答1:
From Facebook API v2.4, we need to explicitly specify fields(ex:email) to get.
Introducing Graph API v2.4
So, you need to have fields as URL parameter like
"https://graph.facebook.com/me?fields=id,email,gender,link,locale,name,timezone,updated_time,verified"
回答2:
As the author of satellizer explains here
https://github.com/sahat/satellizer/issues/116
The format of the scope property should be an array of strings. So yours should be:
Scope: ['email', 'public_profile']
Hope that helps!
Joel
回答3:
In order to get email from Facebook, you must make sure that the account's email is set to public, else it won't return it.
来源:https://stackoverflow.com/questions/31502362/satellizer-facebook-login-not-returning-the-right-scope