Skip to content

Instantly share code, notes, and snippets.

@turicas
Created November 18, 2011 20:16
Show Gist options
  • Save turicas/1377625 to your computer and use it in GitHub Desktop.
Save turicas/1377625 to your computer and use it in GitHub Desktop.
Get the number of followers and following on Twitter
alvaro@ideas:~$ ipython --no-banner -i followers_following.py
In [1]: number_of_following('turicas')
Out[1]: 627
In [2]: number_of_followers('turicas')
Out[2]: 1253
import urllib
import json
URL_API = 'https://api.twitter.com/1/'
def number_of_following(username):
url = URL_API + 'friends/ids.json?cursor=-1&screen_name=' + username
following = urllib.urlopen(url)
contents = following.read()
list_of_following = json.loads(contents)['ids']
return len(list_of_following)
def number_of_followers(username):
url = URL_API + 'followers/ids.json?cursor=-1&screen_name=' + username
following = urllib.urlopen(url)
contents = following.read()
list_of_following = json.loads(contents)['ids']
return len(list_of_following)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment