无法通过 Facebook 获取用户电子邮件 api
Not able to fetch user email via facebook api
我在下面使用:
window.fbAsyncInit = function() {
FB.init({
appId : 'my-app-id',
xfbml : true,
version : 'v2.7'
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
并尝试获取如下电子邮件信息:
FB.api('/me?fields=name,email', function (response) {
console.log(response.name + ' --- '+response.email);
});
输出是:Nitesh Kumar --- 未定义
如何获取用户邮箱?
您需要在登录过程中请求邮箱权限:
FB.login(function(response) {
if (response.authResponse) {
//user just authorized your app
}
}, {scope: 'email'});
顺便说一句,这是正确的(也包括最先进的 ES6 箭头函数):
FB.api('/me', {fields: 'name,email'}, (response) => {
console.log(response.name + ' --- ' + response.email);
});
更多信息:http://www.devils-heaven.com/facebook-javascript-sdk-login/
我在下面使用:
window.fbAsyncInit = function() {
FB.init({
appId : 'my-app-id',
xfbml : true,
version : 'v2.7'
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
并尝试获取如下电子邮件信息:
FB.api('/me?fields=name,email', function (response) {
console.log(response.name + ' --- '+response.email);
});
输出是:Nitesh Kumar --- 未定义
如何获取用户邮箱?
您需要在登录过程中请求邮箱权限:
FB.login(function(response) {
if (response.authResponse) {
//user just authorized your app
}
}, {scope: 'email'});
顺便说一句,这是正确的(也包括最先进的 ES6 箭头函数):
FB.api('/me', {fields: 'name,email'}, (response) => {
console.log(response.name + ' --- ' + response.email);
});
更多信息:http://www.devils-heaven.com/facebook-javascript-sdk-login/