Skip to content

Instantly share code, notes, and snippets.

@coto
Last active December 18, 2015 04:39
Show Gist options
  • Save coto/5727214 to your computer and use it in GitHub Desktop.
Save coto/5727214 to your computer and use it in GitHub Desktop.
"""
Use with:
python twitter_friends.py > twitter_friends.csv
JSON Tools:
http://www.jsoneditoronline.org/
http://jsonparser.com/
"""
import urllib2
import json
screen_name = "your_twitter_name"
friends_ids = json.loads(urllib2.urlopen("https://api.twitter.com/1/friends/ids.json?cursor=-1&screen_name="+screen_name).read())
friends_strids = ','.join(str(x) for x in friends_ids["ids"])
friends_json = json.loads(urllib2.urlopen("http://api.twitter.com/1/users/lookup.json?user_id="+friends_strids).read())
for x in friends_json:
print "{},{},\"{}\"".format(x["id_str"], x["screen_name"].encode('utf8'), x["name"].encode('utf8'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment