0

I know this is a frequent issue, so pardon me for asking it again (it's really not a lack of research), I just can't seem to find a way to make Facebook Profile Picture load using Allauth.

I have used http://www.sarahhagstrom.com/2013/09/the-missing-django-allauth-tutorial/ for some tips, they all worked fine, but for Facebook Profile Picture seems to be missing something, the code on models.py responsible to pass the URL for Facebook Profile Picture can't get Facebook User Id

On the code below...

      http://graph.facebook.com/{}/picture?width=40&height=40

... I've tried to use fb_uid and user_id but still doesn't load.

The profile URL is being called on the template as:

      {% if request.user.is_authenticated %}
             <img src="{{ request.user.profile.profile_image_url }}"/>
      {% endif %}

Suggested here How can I get the user's facebook id with django-allauth? by Pennersr also doesn't give me access to users ID.

Thank you

Community
  • 1
  • 1

1 Answers1

2

The facebook api does not allow direct access to the image,You must write code to download the response from facebook profile url to your server and use your copy of the image.

The above code gives you URL which facebook redirects to their storage,so use

url = "http://graph.facebook.com/%s/picture?type=large" % response['id']
avatar = urlopen(url)
profile = user.get_profile()
profile.profile_photo.save(slugify(user.username + " social") + '.jpg', 
                        ContentFile(avatar.read()))              
profile.save()

But this approach is not recommended as it will cause delay in response,Some recommend celery background task to download the image,so look into that too.

Sai Prasanna
  • 684
  • 1
  • 10
  • 25