0

I have the code to grab a specific users followers as shown below. What I would like to do to further this is not just grab a user's followers but also the followers own followers. An example would be to grab Carl Icahns followers id's and then get those followers own followers id's. So if I am following Carl Icahn, I would be able to retrieve all of my followers as well. Also, for some reason I am grabbing the same 5000 followers each call for some reason instead of getting a different 5000 every time. Can anyone please help me with this? I would greatly appreciate it.

import logging
import time
import csv
import twython
import json

app_key = "**********"
app_secret = "**********"
oauth_token = "***********"
oauth_token_secret = "**************"

twitter = twython.Twython(app_key, app_secret, oauth_token, oauth_token_secret)

followers = twitter.get_followers_ids(screen_name = "Carl_C_Icahn")

for follower_id in followers:
    print ("Carl Icahn followers:", followers)

    with open('carlfollowers.txt', 'a') as outfile:
         json.dump(followers, outfile, sort_keys = True, indent = 4)
pnuts
  • 58,317
  • 11
  • 87
  • 139
  • you should place with statement above for cicle, also use follower_id instead followers in last several lines – josifoski Mar 17 '15 at 03:58

1 Answers1

0

Little change in your code:

import logging  
import time  
import csv  
import twython  
import json  

app_key = "**********"  
app_secret = "**********"  
oauth_token = "***********"  
oauth_token_secret = "**************"  

twitter = twython.Twython(app_key, app_secret, oauth_token, oauth_token_secret)  

followers = twitter.get_followers_ids(screen_name = "Carl_C_Icahn")  

with open('carlfollowers.txt', 'a') as outfile:  
    for follower_id in followers:
        print("Carl Icahn follower:", follower_id)
        json.dump(follower_id, outfile, sort_keys = True, indent = 4)
josifoski
  • 1,696
  • 1
  • 14
  • 19
  • This code doesn't work. All it does is output: "('Carl Icahn follower:', u'previous_cursor') ('Carl Icahn follower:', u'previous_cursor_str') ('Carl Icahn follower:', u'next_cursor') ('Carl Icahn follower:', u'ids') ('Carl Icahn follower:', u'next_cursor_str')" – Justin6493 Mar 17 '15 at 20:56
  • How can I grab a user total followers and not be limited to 5000 of his 200k? – Justin6493 Mar 25 '15 at 15:42
  • for twitter, one console python solution http://rainbowstream.readthedocs.org/en/latest/ , one ruby console solution https://github.com/sferik/t I use this second one @Justin6493 – josifoski Mar 25 '15 at 19:40