我想使用Facebook的API,提供first_name
,last_name
,gender
,email
,birthday
在我的网站上注册。我使用了Graph API,并生成了具有必要范围的访问令牌。我尝试使用个人帐户创建应用程序,并正确返回了字段,但是对于FB测试用户和朋友的帐户,它返回的电子邮件和生日均为“未定义”。在graph.facebook.com中,它显示了朋友帐户的以下错误。
Facebook返回我朋友在doulingo上相同帐户的电子邮件ID。
我设置的权限不正确还是有其他问题?
我的代码的问题全是因为未使用access_token。我用的access_token检索所有,first_name
,last_name
,gender
,birthday
,email
。
function authUser() {
FB.login(checkLoginStatus, {scope:'email, user_likes'});
function checkLoginStatus(response) {
if(!response || response.status !== 'connected') {
alert('User is not authorized');
document.getElementById('loginButton').style.display = 'block';
} else {
alert('User is authorized');
document.getElementById('loginButton').style.display = 'none';
console.log('Access Token: ' + response.authResponse.accessToken);
//This has to be in your callback!
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
// access token is very important to get some fields like email, birthday
getData();
}
}
}
function getData() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.' + response.id);
});
};
因此您获取了访问令牌,但是您做了什么呢?