Pra*_*nik 12 email jquery scope facebook-graph-api facebook-access-token
我试图使用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);
});
};
Run Code Online (Sandbox Code Playgroud)