如何使用facebook选项登录时获取邮件ID。我创建了一个示例项目,我可以获取用户名,但我无法获取邮件ID。
我的编码正在跟进。
我创建了一个App ID,我在下面的代码中实现它。
window.fbAsyncInit = function () {
FB.init({
appId: '###############',
cookie: true, // enable cookies to allow the server to access
// the session
xfbml: true, // parse social plugins on this page
version: 'v2.5' // use version 2.2
});
FB.getLoginStatus(function (response) {
statusChangeCallback(response);
});
};
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 testAPI() {
var id, eid, Username;
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function (response) {
console.log('Successful login for: ' + response.name);
document.getElementById('status').innerHTML =
'Thanks for logging in, ' + response.name + '!' + response.id + ' ' + response.phoneno + ' ' + response.country;
Username = response.name;
eid = response.email;
id = response.id;
});
$.ajax({
type: 'POST',
contentType: "application/json; charset=utf-8",
url: 'LoginWithFB.aspx/fbacctdeta',
data: "{Username:'" + Username + "',eid:'" + eid + "',id:'" + id + "'}",
async: true,
success: function () {
alert(data);
}
});
}
答案 0 :(得分:1)
只有在Facebook完成对您的应用的应用审核后,您才可以在Facebook for Developers
的开发者选项中获取邮件ID和其他信息获取客户信息
FacebookClient fb = new FacebookClient();
dynamic info=fb.Get("\me");