我不知道我的脚本发生了什么,它运行得很好,然后突然不返回电子邮件(返回未定义),但名字、姓氏和用户名工作正常。
这是代码
<script type="text/javascript">
// initialize the library with the API key
FB.init({ appId: 'XXXXXXXXXX',status: true, cookie: true, xfbml: true, oauth: true });
function login() {
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 + '.email :' + response.email);
console.log('Good to see you, ' + ",gender:" + response.gender + "another : " + response.first_name);
console.log('Good to see you, ' + response.username + '.last_name :' + response.last_name);
// console.log('Good to see you, ' + response);
}, { scope: 'email' });
} else {
console.log('User cancelled login or did not fully authorize.');
}
});
}
</script>
虽然我没有改变任何东西,可能出了什么问题?
最佳答案
要获取电子邮件,需要将 {scope: 'email' }
传递给 FB.login
,不作为 FB.api
的参数。
FB.login(function (response) {
...
}, { scope: 'email' });
关于javascript - Facebook 登录脚本停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13910608/