0

I am new to python and Twython and I want to fetch a list of all followers of a user and hence I am using this code

twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
followers = twitter.get_followers_list(screen_name = "abcd")

for theList in followers:
    id = theList[ 0 ]
    print id

But I am getting errors. This may be due to the last 3 line.

coder
  • 183
  • 9

1 Answers1

1

get_followers_list returns json object, you can retrieve the fields from json object using the name of the fields,below is an example for the same.

next_cursor = -1

while(next_cursor):

search = twitter.get_followers_list(screen_name='abcd',cursor=next_cursor)

for result in search['users']:
    time_zone =result['time_zone'] if result['time_zone'] != None else "N/A"
    print result["name"].encode('utf-8')+ ' '+time_zone.encode('utf-8')
next_cursor = search["next_cursor"]
BJC
  • 491
  • 3
  • 21