使用 facebook API javascript 获取电子邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31330694/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using facebook API javascript getting email
提问by Steven Montero Cordero
I have this method and I want to get the email of a person and Send email=undefined.
我有这个方法,我想获取一个人的电子邮件并发送电子邮件=未定义。
First Try:
第一次尝试:
function testAPI() {
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.email + '.');
alert('Good to see you, ' + response.email + '.');
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, {scope:'email'});
I was searching and i found that I have to use {scope:image} and if i put it, dont show me the alert
我正在搜索,我发现我必须使用 {scope:image} 并且如果我放了它,请不要向我显示警报
回答by Andrea
Replacing this
更换这个
FB.api('/me', function(response) {
// ...
with this
有了这个
FB.api('/me?fields=id,name,email,permissions', function(response) {
console.log(response.name);
console.log(response.email);
// ...
I can get the user's email.
我可以得到用户的电子邮件。
回答by njmwas
Or use
或使用
FB.init('/me', {"fields":"id,name,email,first_name,last_name"}, function(response){
console.log(response.email);
});
回答by Giovanni Di Gregorio
Your syntax is wrong, that's the correct one:
你的语法是错误的,这是正确的:
function testAPI() {
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.email + '.');
alert('Good to see you, ' + response.email + '.');
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
},
{scope:'email'}
);
}
where the {scope:'email'}
is inside the )as second argument of the FB.login
其中{scope:'email'}
是内部的)作为的FB.login的第二个参数