[PYTHON] Hit the Twitter API after Oauth authentication with Django

Origin

--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.

What Happens When You Do OAuth Authentication With 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.

qiita0000.png

--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

Hit the Twitter API after Oauth authentication with Django
Twitter OAuth with Django
Qiita API Oauth with Django
Specifying the date with the Twitter API
Hit the Etherpad-lite API with Python
Sample to use after OAuth authentication of BOX API with Python
Tweet regularly with the Go language Twitter API
Try slack OAuth authentication with flask (Slack API V2)
Create an API with Django
Use Twitter API with Python
Try using the Twitter API
Try using the Twitter API
Support yourself with Twitter API
Call the API with python3.
Successful update_with_media with twitter API
Streamline information gathering with the Twitter API and Slack bots
Hit the Sesami API in Python
[Python] Hit the Google Translation API
Twitter posting application made with Django
Hit the web API in Python
Hit the top command with htop
GraphQL API with graphene_django in Django
Access the Twitter API in Python
Create a REST API to operate dynamodb with the Django REST Framework
Hit ISE's ERS API with PowerShell
I tried to get the authentication code of Qiita API with Python.
Hit a method of a class instance with the Python Bottle Web API
Be careful when retrieving tweets at regular intervals with the Twitter API
Collecting information from Twitter with Python (Twitter API)
Access the Docker Remote API with Requests
Your own Twitter client made with Django
Tweet using the Twitter API in Python
I'm having trouble with Django's Twitter authentication
Post from another account with Twitter API
Get holidays with the Google Calendar API
Extract sudden buzzwords with twitter streaming API
Play with puns using the COTOHA API
Try hitting the Spotify API in Django.
The easiest way to get started with Django
Build the fastest Django development environment with docker-compose
Recreate the django staff registration screen with class
Hit the Web API using requests Example: Flickr
Until you use the Kaggle API with Colab
Hit Cognito-authenticated AppSync from behind with IAM authentication
Hit the Firebase Dynamic Links API in Python
Implementing authentication in Django REST Framework with djoser
Display the image after Data Augmentation with Pytorch
It's too easy to access the Twitter API with rauth and I have her ...
Second half of the first day of studying Python Try hitting the Twitter API with Bottle