--There were many articles that implemented login on Twitter using Oauth authentication when I wanted to make a Twitter client with Django.
――But what I wanted to do was to hit the Twitter API using the oauth_token and secret issued when Oauth authentication was performed. ――I was struggling because I couldn't find the article because I wasn't sure how to google, but I was able to put an end to it, so I will write it as an article --I used a library called `social-auth-app-django.
--Looking at the log when returning from the Twitter site, you can see that oauth_token and secret are added as queries to the path / complete / twitter
and a GET request is being made.
――At first, I thought that it would override the method that runs when the path complete / twitter
is accessed, but it seems to be different.
--User model object is generated when Oauth authentication is performed with Django
--When I logged in as a super user from host / admin
and looked at user management, it was true that a user was created with the screen name of Twitter.
of
SOCIAL_DJANGO`--It seems that you should refer to the UserSocialAuth model. --Since UserSocialAuth exists as a model of social_django
from social_django.models import UserSocialAuth
UserSocialAuth.objects.get(Query).access_token
You can get the dictionary containing oauth_token and secret with, so you can hit the Twitter API.
Recommended Posts