Open GoogleCodeExporter opened 8 years ago
Sorry, seems that for example following call doesn't work:
users = api.GetFollowers(87053066)
(I am using the cursor paging now)
Original comment by kill...@gmail.com
on 22 Aug 2010 at 7:37
Can someone PLEASE give a working example of using cursors to return all
followers?
I keep hitting the 100 user returns. It is not paging.
8< -------------
me = api.GetUser("rrdearman")
# work out the # of page calls
numpages = int(math.ceil(me.followers_count/100.0))
followerpage = (api.GetFollowers(page=x) for x in range(1,numpages+1))
# loop and get followers
myfollower = (y[z]
for y in followerpage \
for z in range(len(y)))
------------->8
Original comment by rick.dea...@gmail.com
on 20 Sep 2011 at 2:20
Got a copy of 0.8.3 which has a fix that allows the GetFollowers() function to
attempt to get all the followers. Interestingly this seems to make me hit the
Rate Limit of Twitter.
twitter.TwitterError: Rate limit exceeded. Clients may not make more than 350
requests per hour.
I have about 3500 followers. Anyone have any suggestions? Paging didn't work,
and with a version without paging, I hit rate limits.
Any help is greatly appreciated.
Original comment by rick.dea...@gmail.com
on 20 Sep 2011 at 7:14
As long as you don't have a developer API access you can only make a limited
number of requests per hour.
Original comment by kill...@gmail.com
on 20 Sep 2011 at 7:18
I have re-written the GetFollowers() and it works for me. Someone should check
it though. I don't know how to (and not really interested in) merging into
source. I have 3500+ followers and it works a treat for me. This function will
probably fail if you hit the rate limit of 350 requests. (i.e. you have more
than 35,000 followers)
=====================
def GetFollowers(self, cursor=-1, rate_limit=350):
'''Fetch the sequence of twitter.User instances, one for each follower
The twitter.Api instance must be authenticated.
Args:
cursor:
Specifies the Twitter API Cursor location to start at. [Optional]
Note: there are pagination limits.
rate_limit:
Specifies the Twitter rate limit. Defaults to 350. Individuals are limited
to 150
Returns:
A sequence of twitter.User instances, one for each follower
'''
if not self._oauth_consumer:
raise TwitterError("twitter.Api instance must be authenticated")
url = '%s/statuses/followers.json' % self.base_url
result = []
rate_check = 1
while True:
parameters = { 'cursor': cursor }
json = self._FetchUrl(url, parameters=parameters)
data = self._ParseAndCheckTwitter(json)
result += [User.NewFromJsonDict(x) for x in data['users']]
if 'next_cursor' in data:
cursor = data['next_cursor']
if data['next_cursor'] == 0 or data['next_cursor'] == data['previous_cursor']:
break
else:
break
if rate_check == rate_limit:
break
else:
rate_check += 1
return result
====================
Original comment by rick.dea...@gmail.com
on 21 Sep 2011 at 2:45
Original issue reported on code.google.com by
kill...@gmail.com
on 22 Aug 2010 at 12:24