Get Facebook user likes in Python Social Auth

前端 未结 1 428
既然无缘
既然无缘 2021-01-07 12:30

I\'m starting a project with Django and I\'m trying to allow users log in with Facebook. For the site purposes, I want to store the user likes in my database.

I took

相关标签:
1条回答
  • 2021-01-07 12:46

    Rename the setting SOCIAL_AUTH_SCOPE to SOCIAL_AUTH_FACEBOOK_SCOPE. Likes aren't sent automatically in the auth process, you need to query them to Facebook API, for example:

    def get_likes(strategy, details, response, *args, **kwargs):
        if strategy.backend.name == 'facebook':
            likes = strategy.backend.get_json(
                'https://graph.facebook.com/%s/likes' % response['id'],
                params={'access_token': response['access_token']}
            )
            for like in likes['data']:
                pass  # Process and save likes here
    
    0 讨论(0)
提交回复
热议问题