Search code examples
pythondjangoapitwitterdjango-allauth

Using django-allauth for authorized Twitter API actions


I'm trying to build an app that interacts with the Twitter API (posting statuses, toggling settings, etc.). I've found django-allauth to simplify log-in, etc., and I like what it does.

The problem is that allauth seems to only authenticate the user; it doesn't appear to authorize my app to work on a users behalf. Can anyone point me to a resource where I can see how to tap into the allauth data to create an authorization? (if that even exists) Thanks!


Solution

  • For that you need to understand more about the Twitter APIs. Check the developer section of twitter and see available apis for pulling the data using access token. Once you've understanding on that, then what you need to do is just fetch the authenticated user access token like this (I'vent tested this but I hope this will work.)

    social = user.social_auth.get(provider='twitter')
    access_token = social.extra_data['access_token']['token']
    

    Now you have the access_token on authenticated user so you can use any python library like requests, urllib2 or even there might be wrappers written on top of those and can pull the data. Hope this helps you. :)