5

I'm trying to extract followers ids from a user who has more than 5000 followers. I'm just testing so i'm doing it in the interpreter for now. I'm doing it this way.

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
ids = api.followers_ids(user_id='userfoo',cursor='-1')
print ids

It gets the first cursor fine but where is the next_cursor return value stored? Its not in my ids variable like it is should be because it has been parsed. What do I need to call to Print the next_cursor value?

Example

>>>print next_cursor

Is it possible? Iv'e looked everywhere but can't seem to find much documentation on this.

TysonU
  • 432
  • 4
  • 18
  • Look at this link: http://stackoverflow.com/questions/17431807/get-all-follower-ids-in-twitter-by-tweepy – Pymal Jun 10 '15 at 05:59

1 Answers1

-1

Change:

ids = api.followers_ids(user_id='userfoo',cursor='-1')

to:

ids = api.followers_ids(user_id='userfoo',cursor='-1').pages()

You can now loop through it to get the values:

all_ids = []
for p in ids:
    all_ids.append(p)

The cursor values will be stored in ids.

Without looping through, because you're still on the first page of the cursor, if you tried to print it now it would probably still be -1.

To get the next 5000, use ids.next(). This will give you the next 5000. Your cursor will now have moved forward a page. ids.next_cursor should now give you the cursor for the next page of followers.

You can iterate forward and backward using ids.next() and ids.prev(). You can then see the cursors using ids.next_cursor and ids.prev_cursor.

Reen
  • 399
  • 1
  • 5
  • 12