redeemefy
redeemefy

Reputation: 4849

Requests.get Twitter API Bad Authentication

I'm trying to requests.get() twitter from their API for a Data Science work. I'm trying to follow documentation but is kind of confusing to me. Here is my code...

import requests
import oauth2 as o

consumer_key = 'sdfgsdfgsdfgsdfgsdfg'
consumer_secrete = 'sadfasdfgasdfasdfasdfasdfasdf'
consumer = o.Consumer(key=consumer_key, secret=consumer_secrete)

access_token = 'asdfasdfsadfasdfasdf'
access_token_secret = 'asdfasdfasdfasdfasdf'
acc_token = o.Token(key=access_token, secret=access_token_secret)

client = o.Client(consumer, acc_token)

base_url = 'https://api.twitter.com/1.1/search/tweets.json?q=%22I%20want%20to%20take%20my%20life%20away%22%20near%3A%22Grove%20South%22%20within%3A1500mi&src=typd'

data = requests.get(base_url, client)
print(data)

I'm getting a 400 Response. There are so many modules and libraries in Python that is hard to know if it is compatible with Python 3 in the first place, then if it is compatible with the API. It is kind of confusing. Does anybody know if I can do this with requests and oauth2 or I need to change my approach?

Upvotes: 0

Views: 125

Answers (1)

Alex
Alex

Reputation: 1522

I've used Twython in the past with great results.

From their documentation:

from twython import Twython
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)

Upvotes: 1

Related Questions