使用 javascript sdk api v2.4 从 Facebook 获取 'email' 时出现问题
Problems fetching 'email' from Facebook using javascript sdk api v2.4
我正在使用 Javascript 的 FB 登录文档中的代码。但它不会获取用户的电子邮件地址。它适用于旧版本......但它不适用于我的应用程序版本(v2.4)。我也在使用 facebook 登录按钮。
这是我得到的:
function statusChangeCallback(response) {
console.log('statusChangeCallback');
console.log(response);
if (response.status === 'connected') {
testAPI();
} else if (response.status === 'not_authorized') {
document.getElementById('status').innerHTML = 'Please log ' +
'into this app.';
} else {
document.getElementById('status').innerHTML = 'Please log ' +
'into Facebook.';
}
}
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
}
window.fbAsyncInit = function() {
FB.init({
appId: '1650558335190396',
cookie: true,
xfbml: true,
version: 'v2.4'
});
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/es_LA/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
} (document, 'script', 'facebook-jssdk'));
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Successful login for: ' + response.name + response.id);
document.getElementById('status').innerHTML =
'Thanks for logging in, <br>' + response.name + '<br>' + response.id + '<br> <img src="http://graph.facebook.com/' + response.id + '/picture" /></br>' + response.email;
});
}
这是按钮部分:
<fb:login-button scope="email,user_birthday,user_about_me" autologoutlink="true" onlogin="checkLoginState();">
</fb:login-button>
FB.api('/me?fields=name,email', function(response) {...
在更新日志中搜索 "Declarative Fields":https://developers.facebook.com/docs/apps/changelog#v2_4
我正在使用 Javascript 的 FB 登录文档中的代码。但它不会获取用户的电子邮件地址。它适用于旧版本......但它不适用于我的应用程序版本(v2.4)。我也在使用 facebook 登录按钮。
这是我得到的:
function statusChangeCallback(response) {
console.log('statusChangeCallback');
console.log(response);
if (response.status === 'connected') {
testAPI();
} else if (response.status === 'not_authorized') {
document.getElementById('status').innerHTML = 'Please log ' +
'into this app.';
} else {
document.getElementById('status').innerHTML = 'Please log ' +
'into Facebook.';
}
}
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
}
window.fbAsyncInit = function() {
FB.init({
appId: '1650558335190396',
cookie: true,
xfbml: true,
version: 'v2.4'
});
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/es_LA/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
} (document, 'script', 'facebook-jssdk'));
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Successful login for: ' + response.name + response.id);
document.getElementById('status').innerHTML =
'Thanks for logging in, <br>' + response.name + '<br>' + response.id + '<br> <img src="http://graph.facebook.com/' + response.id + '/picture" /></br>' + response.email;
});
}
这是按钮部分:
<fb:login-button scope="email,user_birthday,user_about_me" autologoutlink="true" onlogin="checkLoginState();">
</fb:login-button>
FB.api('/me?fields=name,email', function(response) {...
在更新日志中搜索 "Declarative Fields":https://developers.facebook.com/docs/apps/changelog#v2_4