我使用v2.2已经很长时间了,一切运转良好。 但是我出于某种原因需要升级到v2.8并且电子邮件的检索不再起作用。 谁能告诉我代码应该是什么样的?
使用检索电子邮件地址的v2.2代码:
FB.api('/me', function(response) {
var fn = ('first_name' in response) ? response.first_name : "null";
var ln = ('last_name' in response) ? response.last_name : "null";
var fid = ('id' in response) ? response.id : "null";
var mail = ('email' in response) ? response.email : "null";
...
});
通过以下方式进行初始化:
FB.init({
appId : 'myid',
cookie : true,
xfbml : true,
version : 'v2.8'
});
登录(当然也是在API调用之前完成)如下所示:
FB.login(function(response) {
if (response.authResponse) {
processLogin(response);
} else {
// user clicked cancel
}
}, {scope: 'public_profile,email'});
解决方案
这是使用"声明字段"的工作v2.8解决方案。在API调用中:
FB.api('/me', {fields: 'first_name,last_name,email,id'}, function(response) {
var fn = ('first_name' in response) ? response.first_name : "null";
var ln = ('last_name' in response) ? response.last_name : "null";
var fid = ('id' in response) ? response.id : "null";
var mail = ('email' in response) ? response.email : "null";
...
});
答案 0 :(得分:2)
FB.api('/me', {fields: 'name,email'}, (response) => {
console.log(response);
});
它被称为“声明字段”,随附图API的v2.4:https://developers.facebook.com/docs/apps/changelog#v2_4