如何在Django-allauth中获取Google的生日日期?
我想通过Django-Allauth从Google的OAuth获取生日日期,但一直没成功。
我看到需要添加一个范围(scope)"https://www.googleapis.com/auth/plus.me",但是在extra_data字段里什么都没有显示。
你能帮我吗?谢谢!
编辑:示例代码:
SOCIALACCOUNT_PROVIDERS = {
'facebook':
{'SCOPE': ['publish_stream', 'email', 'user_birthday', 'user_location'],
'AUTH_PARAMS': {'auth_type': 'https'},
'METHOD': 'oauth2',
'VERIFIED_EMAIL': True},
'google':
#{ 'SCOPE': ['https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email',],
{ 'SCOPE': ['https://www.googleapis.com/auth/plus.login', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/plus.me'],
'AUTH_PARAMS': { 'access_type': 'online' },
} }
在Facebook上可以正常工作,我能获取到额外的信息,比如生日、性别等等。但在Google上,extra_data字段没有填充新的信息。
1 个回答
0
为了满足我在学术项目中的需求,我对 django-allauth 进行了修改,增加了一些功能,比如额外的谷歌个人资料数据。
你可以通过 pip 来安装这个包。
pip install django-allauth-underground
将谷歌的权限设置为:
SOCIALACCOUNT_PROVIDERS = {
'google': {
'SCOPE': [
'https://www.googleapis.com/auth/user.birthday.read',
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile'
],
'AUTH_PARAMS': {
'access_type': 'online',
}
},
}
在成功注册后,额外的数据会更新为一些 真实的额外数据,这些数据可以通过 extra_data['people']
来访问。