Facebook SDK:有时电子邮件字段返回null(带有“电子邮件”权限集) [英] Facebook SDK : sometimes email field return null ( with "email" permission set )
问题描述
我知道电子邮件权限允许Facebook App获取主要电子邮件地址在用户个人资料中说明,但为什么SDK有时会返回 null
?
email是允许用户在允许应用时不需要给予的扩展权限。如果您需要用户在继续使用应用程序之前授予电子邮件权限,则需要在允许用户在身份验证之后继续工作流程时检查该权限。
您需要使用的图形API端点是
/ me / permissions
这是一种方法我使用这样做:
权限
是一个表示所请求权限的字符串数组。
hasPermissions([email],function(hasPerms){
alert(hasPerms);
});
函数hasPermissions(权限,回调){
console.log(perms requested);
console.log(permissions);
FB.api(/ me / permissions,function(response){
var hasPerms = true;
console.log(perms getsd);
console.log (响应);
为(var i in permissions){
console.log([permissions [i]] + - + response [data] [0] [permissions [i]] )
hasPerms = hasPerms&& response [data] [0] [permissions [i]] == 1;
}
if(typeof callback ==function {
callback(hasPerms);
}
});
}
I have a Facebook App written in PHP. Asked for user's "email" permission. I noticed that I obtained 90% of user's email address, but not some.
I know that the email permission allows Facebook App to get the primary email address stated in user's profile, but why does the SDK sometimes return null
?
"email" is an extended permission that users are not required to give when allowing an application. If you need your users to grant the "email" permission before continuing in your app, you need to check that that permission is present before allowing the user to continue his workflow after authentication.
the graph API endpoint you need to use is "/me/permissions"
Here is a method that I use to do just that:
permissions
is an array of strings that represent the permissions requested.
hasPermissions(["email"], function(hasPerms){
alert(hasPerms);
});
function hasPermissions(permissions, callback){
console.log("perms requested");
console.log(permissions);
FB.api("/me/permissions", function(response){
var hasPerms = true;
console.log("perms obtaind");
console.log(response);
for(var i in permissions){
console.log([permissions[i]] + " - " + response["data"][0][permissions[i]])
hasPerms = hasPerms && response["data"][0][permissions[i]] == 1;
}
if(typeof callback == "function"){
callback(hasPerms);
}
});
}
这篇关于Facebook SDK:有时电子邮件字段返回null(带有“电子邮件”权限集)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!