gpt4 book ai didi

javascript - Facebook 登录中电子邮件的未定义值

转载 作者:行者123 更新时间:2023-11-28 18:55:18 25 4
gpt4 key购买 nike

我想从 facebook 获取用户电子邮件 ID 我用于获取电子邮件 ID 的用户 Java 脚本 SDK

  <script>

(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "https://connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));

$(document).ready(function() {
$('#fb_button').click(function() {
FB._https = (window.location.protocol == "https:"); // Required because FB Javascript SDK tries to submit https to http
FB.init({appId:"{app_id}", cookie:true, status:true, xfbml:true, oauth:true , version:'v2.5'});
FB.login(function(response) {

if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
console.log(response); // dump complete info
access_token = response.authResponse.accessToken; //get access token
user_id = response.authResponse.userID; //get FB UID


FB.api('/me', function(response) {
user_email = response.email; //get user email
alert(user_email);
});
}
else{
alert('no response');
}
}, {
scope: 'email'

});

});
});


(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
// document.getElementById('fb-root').appendChild(e);
}());
</script>

它返回响应但未定义警报值我将相同的代码复制粘贴到另一个具有不同 app_id 的网站中,它返回同一用户的电子邮件 ID。我也尝试过 PHP SDK,但结果相同。可能这个问题是重复的。但我尝试了这些问题的几乎所有答案。

有人知道出了什么问题吗?

提前致谢

最佳答案

“声明性字段”就是您所需要的,请参阅更改日志:https://developers.facebook.com/docs/apps/changelog#v2_4

例如:

FB.api('/me', {fields: 'name,email'}, function(response) {
user_email = response.email; //get user email
alert(user_email);
});

关于javascript - Facebook 登录中电子邮件的未定义值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33730485/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com