Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facebook profile picture #80

Closed
Salma7amed opened this issue Nov 10, 2013 · 3 comments
Closed

Facebook profile picture #80

Salma7amed opened this issue Nov 10, 2013 · 3 comments

Comments

@Salma7amed
Copy link

I had a question, How to store the facebook profile picture of a user while logging in through facebook.

I found this link which says how to do so using django-social-app, https://gist.github.com/kalamhavij/1662930.

How can I do the same using python-social-app ??

@omab
Copy link
Owner

omab commented Nov 10, 2013

@Salma7amed, try with a code like this

from requests import request, HTTPError

from django.core.files.base import ContentFile


def save_profile_picture(strategy, user, response, details, is_new=False,
                         *args, **kwargs):
    # Save Facebook profile photo into a user profile, assuming a profile model
    # with a profile_photo file-type attribute
    if is_new and strategy.backend.name == 'facebook':
        url = 'http://graph.facebook.com/{0}/picture'.format(response['id'])

        try:
            response = request('GET', url, params={'type': 'large'})
            response.raise_for_status()
        except HTTPError:
            pass
        else:
            profile = user.get_profile()
            profile.profile_photo.save('{0}_social.jpg'.format(user.username),
                                       ContentFile(response.content))
            profile.save()

Put that into the pipeline and it should do the trick. The code wasn't tested, but should help to get you started).

@omab omab closed this as completed Nov 10, 2013
@Salma7amed
Copy link
Author

Thanks a lot it did work (Y).

@mr-semih
Copy link

mr-semih commented Mar 6, 2021

What if we have the ImageField instead of FileField ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants