Ale*_*lla 4 python google-login google-plus python-social-auth
有没有办法使用python social auth获取Google个人资料图片网址?
所以,这就是我为facebook和twitter所做的事情,用这段代码添加一个管道:
if strategy.backend.name == 'facebook':
url = 'http://graph.facebook.com/{0}/picture'.format(response['id'])
elif strategy.backend.name == "twitter":
if response['profile_image_url'] != '':
url = response['profile_image_url']
elif strategy.backend.name == "GoogleOAuth2": # doesn't work
user_id = response['id']
url = "???"
Run Code Online (Sandbox Code Playgroud)
首先,我不知道后端的名称是什么,是"GoogleOAuth2"吗?第二,我应该用什么网址来保存个人资料的头像?这是这样的吗?
from social.backends.google import GoogleOAuth2
def save_profile(backend, user, response, *args, **kwargs):
if isinstance(backend, GoogleOAuth2):
if response.get('image') and response['image'].get('url'):
url = response['image'].get('url')
ext = url.split('.')[-1]
user.avatar.save(
'{0}.{1}'.format('avatar', ext),
ContentFile(urllib2.urlopen(url).read()),
save=False
)
user.save()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3293 次 |
| 最近记录: |