How to execute oauth when running twitter utility with python requests

I am trying to restore the last 100 user tweets. It works well with the tweepy module in Python. But how can I do the same with queries in python. I want to make:

import requests r = requests.get('https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=xxxx&count=100') 

Here, how to authenticate n with the client key, client secret key, access key and access secret, before sending this request?

+5
source share
1 answer

You can use requests-oauthlib as described in the docs requests.

OAuth:

 import requests from requests_oauthlib import OAuth1 url = 'https://api.twitter.com/1.1/account/verify_credentials.json' auth = OAuth1(API_KEY, API_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET) requests.get(url, auth=auth) 

Get tweets:

 r = requests.get('https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=stackoverflow&count=100', auth=auth) for tweet in r.json(): print tweet['text'] 
+10
source

Source: https://habr.com/ru/post/1234396/


All Articles