It's too easy to access the Twitter API with rauth and I have her ...

I needed to access the Twitter API, so I tried implementing it myself, but ... well ... I mean ... it was a hassle. So, when I searched for a library, I found a library called rauth, so I tried it.

Since it is an OAuth library (not Twitter library), APIs other than Twitter can be used as long as it is OAuth authentication. Also, it depends on Requests, and it feels good to be able to write the code of the HTTP request part neatly.

Below is a sample of muttering'rauth'on my timeline. "Hey, isn't it easy?"

rauth_sample


import rauth

# access_token/access_token_Premise of getting a secret
session = rauth.OAuth1Session(
    "consumer_key",
    "consumer_secret",
    "access_token",
    "access_token_secret")

#There is a way to set the baseURL to session, but it is omitted.
session.post(
    'https://api.twitter.com/1.1/statuses/update.json',
    data={'status': 'rauth'})

In the above sample, it is assumed that access_token / access_token_secret has been acquired in advance, but as far as the README is seen, it seems that it is not so difficult to acquire. Let's try this again soon.

By the way, she couldn't.

Postscript

API baseURL can be omitted by setting OAuth1Service to OAuth1Session.

rauth_sample_set_service


twitter = rauth.OAuth1Service(
    name='twitter',
    consumer_key='consumer_key',
    consumer_secret='consumer_secret',
    request_token_url='https://api.twitter.com/oauth/request_token',
    access_token_url='https://api.twitter.com/oauth/access_token',
    authorize_url='https://api.twitter.com/oauth/authorize',
    base_url='https://api.twitter.com/1.1/')

session = rauth.OAuth1Session(
    consumer_key='consumer_key',
    consumer_secret='consumer_secret',
    access_token='access_token',
    access_token_secret='access_token_secret',
    service=twitter)

#The baseURL set in Service can be omitted
res = session.get(
    url='statuses/home_timeline.json',
    params={'count': 10})
print(res.json())

Recommended Posts

It's too easy to access the Twitter API with rauth and I have her ...
I tried follow management with Twitter API and Python (easy)
I tried to automate internal operations with Docker, Python and Twitter API + bonus
I tried to score the syntax that was too humorous and humorous using the COTOHA API.
Easy to use Nifty Cloud API with botocore and python
It's too easy to use an existing database with Django
Streamline information gathering with the Twitter API and Slack bots
I tried to automatically post to ChatWork at the time of deployment with fabric and ChatWork Api
Specifying the date with the Twitter API
Grant an access token with the curl command and POST the API
Access the Twitter API in Python
I tried to delete bad tweets regularly with AWS Lambda + Twitter API
I tried to express sadness and joy with the stable marriage problem.
I tried to get the authentication code of Qiita API with Python.
Search for Twitter keywords with tweepy and write the results to Excel
Sample code to get the Twitter API oauth_token and oauth_token_secret in Python 2.7
I tried to learn the angle from sin and cos with chainer
I tried to get the movie information of TMDb API with Python
I tried to control the network bandwidth and delay with the tc command
Access the Docker Remote API with Requests
I tried to touch the COTOHA API
I can't use the "next_results" parameter in the Twitter API Search API! ?? Causes and remedies
When I tried to change the root password with ansible, I couldn't access it.
[Introduction to AWS] I tried porting the conversation app and playing with text2speech @ AWS ♪
I tried to make a simple image recognition API with Fast API and Tensorflow
Tweet regularly with the Go language Twitter API
I tried to save the data with discord
I wanted to play with the Bezier curve
I tried to touch the API of ebay
I want to analyze songs with Spotify API 1
I tried to notify the update of "Become a novelist" using "IFTTT" and "Become a novelist API"
I tried to automate the article update of Livedoor blog with Python and selenium.
How to change the behavior when loading / dumping yaml with PyYAML and its details
I just wanted to extract the data of the desired date and time with Django
I tried to compare the processing speed with dplyr of R and pandas of Python
It is easy to execute SQL with Python and output the result in Excel
I tried to learn the sin function with chainer
I tried to read and save automatically with VOICEROID2 2
Easy IoT to start with Raspberry Pi and MESH
I tried to implement and learn DCGAN with PyTorch
I want to handle optimization with python and cplex
[Introduction to WordCloud] It's easy to use even with Jetson-nano ♬
I tried to touch the CSV file with Python
I tried to solve the soma cube with python
I tried to automatically read and save with VOICEROID2
It's too troublesome to display Japanese with Vim's python3.
I want to inherit to the back with python dataclass
Crawling with Python and Twitter API 1-Simple search function
It's not easy to write Python, it's easy to write numpy and scipy
I tried to uncover our darkness with Chatwork API
Post to your account using the API on Twitter
Get comments and subscribers with the YouTube Data API
I tried to solve the problem with Python Vol.1
I tried to implement Grad-CAM with keras and tensorflow
I moved the automatic summarization API "summpy" with python3.
I tried hitting the API with echonest's python client
I wrote you to watch the signal with Go
A script that makes it easy to create rich menus with the LINE Messaging API
I tried to get the number of days of the month holidays (Saturdays, Sundays, and holidays) with python
I made a server with Python socket and ssl and tried to access it from a browser
I also tried to imitate the function monad and State monad with a generator in Python