gpt4 book ai didi

javascript - 使用 facebook javascript api 发送电子邮件

转载 作者:搜寻专家 更新时间:2023-11-01 05:04:50 24 4
gpt4 key购买 nike

我正在尝试为我的应用获取 facebook 用户电子邮件。但是当我查询时,电子邮件地址返回为 undefined。我不知道如何处理它。

这是我的代码-

<body>
<script>
function statusChangeCallback(response) {
console.log('statusChangeCallback');
console.log(response);

if (response.status === 'connected') {

testAPI();
} else if (response.status === 'not_authorized') {

FB.login(function(response) {}, {
scope: 'email'
});
document.getElementById('status').innerHTML = 'Please log ' +
'into this app.';
} else {
FB.login(function(response) {}, {
scope: 'email'
});
document.getElementById('status').innerHTML = 'Please log ' +
'into Facebook.';
}
}

function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
}

window.fbAsyncInit = function() {
FB.init({
appId: 'app id',
cookie: true, // enable cookies to allow the server to access

xfbml: true, // parse social plugins on this page
version: 'v2.1' // use version 2.1
});

FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});

};

(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'));

function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
alert(response.name);
alert(response.email);
console.log('Successful login for: ' + response.name);
document.getElementById('status').innerHTML = 'Thanks for logging in, ' + response.name + '!';
});
}
</script>
<fb:login-button perms="email" autologoutlink="true" onlogin="checkLoginState();">
</fb:login-button>
<div id="status">
</div>
</body>

最佳答案

@Tobi 这真的拯救了我的一天:

FB.api('/me

替换为

FB.api('/me?fields=id,name,email,permissions', function(response) {
console.log(response.name);
console.log(response.email);
});

但是,我不明白为什么以下代码(在 facebook 文档中)的范围不起作用

<fb:login-button scope="public_profile,email" onlogin="checkLoginState();">

关于javascript - 使用 facebook javascript api 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28066125/

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