0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

DjangoでGoogleのアバター画像を扱う

Posted at

いくつか参考記事があったが、記事の通りやっても下記エラーとなり詰まってたのでメモ。

エラー内容

KeyError at /oauth/complete/google-oauth2/
'image'

解決策

def get_avatar(backend, strategy, details, response,
        user=None, *args, **kwargs):
    url = None
    if backend.name == 'facebook':
        url = "http://graph.facebook.com/%s/picture?type=large"%response['id']
    if backend.name == 'twitter':
        url = response.get('profile_image_url', '').replace('_normal','')
    if backend.name == 'google-oauth2':
        url = response["picture"]  #ここが「image」だと✗だったが、pictureで無事表示できた
    if url:
        user.profile_icon = url 
        user.save()

参考記事:
https://hodalog.com/python-social-auth-get-google-avatar/

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?