My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Request data from Twitter API in json using Python

anuj tyagi's photo
anuj tyagi
·Oct 15, 2016

Anyone used twitter REST API to GET/POST data ? I am using python requests module.. need help.

Initially starting with GET. it should go like this... after adding keys and username :

import requests

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)

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

It's not working for me. Also, what if I don't want to use any third party module like twitter. Just by importing modules like request and json.