[英]How to get a user's email from an access token using the Facebook Python SDK
I am trying to implement Facebook login for an application I am developing. 我正在尝试为我正在开发的应用程序实现Facebook登录。
I am getting an access token like this: 我得到这样的访问令牌:
<!DOCTYPE html>
<html>
<head></head>
<body>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '[Redacted]',
xfbml : true,
version : 'v2.6'
});
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
window.location = "http://[my domain]/FBloginAuth?"+FB.getAuthResponse()["accessToken"]
} else {
window.location = encodeURI("https://www.facebook.com/dialog/oauth?scope=email&client_id=[redacted]&redirect_uri=http://[my domain]/FBloginAuth&response_type=token");
}
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "http://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<div id="status"></div>
</body>
</html>
My server then fishes the access token from the url like this (Python 2, because I have to support the Google OAuth SDK which doesn't seem to support Python 3.): 然后,我的服务器从网址中获取访问令牌,如下所示(Python 2,因为我必须支持似乎不支持Python 3的Google OAuth SDK。):
graph = facebook.GraphAPI(access_token=environ["QUERY_STRING"]) # Apparently there is an extrea
profile = graph.get_object('me')
args = {'fields' : 'id,name,email', }
profile = graph.get_object('me', **args)
print(profile)
I know that this doesn't parse cases where there are variables in the url. 我知道这无法解析网址中存在变量的情况。 That is not the point.
那不是重点。 For now I am hand-feeding the token.
目前,我正在手动输入令牌。 The code vomits:
代码呕吐:
{u'id': u'[redacted]', u'name': u'[redacted]'}
My question is why the email doesn't appear in the response as I set the scope when asking for the token. 我的问题是为什么在我要求令牌时设置范围,为什么电子邮件没有出现在响应中。 Also, what should I do to get the email?
另外,我应该怎么做才能收到电子邮件?
Make sure that 确保
a) the user has actually granted the permission to your app (request /me/permissions
to confirm, using the same access token), and a)用户实际上已经授予了您的应用程序的许可(使用相同的访问令牌请求
/me/permissions
进行确认),以及
b) that their e-mail address is verified with Facebook. b)他们的电子邮件地址已通过Facebook验证。 (Apparently not automatically the case with the e-mail address used to register.)
(显然不是自动使用用于注册的电子邮件地址的情况。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.