Skip to content

Instantly share code, notes, and snippets.

@svineet
Created January 17, 2013 10:55
Show Gist options
  • Save svineet/4555198 to your computer and use it in GitHub Desktop.
Save svineet/4555198 to your computer and use it in GitHub Desktop.
A python program to fetch and print out the last 5 tweets made by a user(taken as input) using the twitter REST api.
import requests
import json
def main():
handle = raw_input('Twitter handle(without @)-')
r = requests.get('https://api.twitter.com/1/statuses/user_timeline/'+handle+'.json?callback=?&count=5')
obj = json.loads(r.content)
for i in range(0,5):
print "-"*24
print obj[i]['user']['name'] + " tweeted -"
print obj[i]['text']
print "Created on " + obj[i]['user']['created_at']
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment