我正在製作一個網站,通過他們的Facebook賬戶登錄。無法獲取用戶通過我的網站的fb賬戶登錄的電子郵件
我能夠獲取名稱和用戶圖像,但我沒有收到用戶的電子郵件。電子郵件正在返回未定義狀態。我對Facebook登錄代碼:
window.fbAsyncInit = function() {
FB.init({
appId : 'XXXXXXXXXXXXXXXX', // Set YOUR APP ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.Event.subscribe('auth.authResponseChange', function(response)
{
if (response.status === 'connected')
{
document.getElementById("message").innerHTML += "<br>";
}
else if (response.status === 'not_authorized')
{
}
});
};
function Login()
{
FB.login(function(response) {
if (response.authResponse)
{
getUserInfo();
getPhoto();
} else
{
console.log('User cancelled login or did not fully authorize.');
}
},{scope: 'email,user_photos,user_videos'});
}
function getUserInfo() {
FB.api('/me', function(response) {
var str="You have succesfully logged in<br>";
var name=response.name;
var email=response.email;
console.log(name+email);
});
$(document).ajaxStop(function(){
window.location.reload();
});
}
function getPhoto()
{
FB.api('/me/picture?type=normal', function(response) {
var str="<br/><b>Pic</b> : <img src='"+response.data.url+"'/>";
$('#getphoto').html(str);
});
}
function Logout()
{
FB.logout(function(){document.location.reload();});
}
// Load the SDK asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
我試着通過堆棧溢出和developers.facebook.com提到的所有方式獲得的電子郵件,但沒有成功。
觸發的Facebook登錄:
<img src='img/fblogin.jpg' onclick='login()'>
我試圖 for (key in response){ alert("response["+ key +"]="+ response[key]); }
它返回名稱和ID提醒響應特性不支持電子郵件
我試圖通過(鑰匙提醒響應特性作爲響應){ alert(「response [」+ key +「] =」+ response [key]); }它返回的名稱和編號不是電子郵件 –