Open GoogleCodeExporter opened 9 years ago
I've attached a patch for this.
The problem with it is in the way that twitter have implemented the new change.
If
you provide no cursor parameter, the API returns a list of users, just like it
does
currently. In order to use the cursors to iterate through the list, you must
make
your initial call with cursor=-1. The JSON call then turns this into a
dictionary
like: {"next_cursor":<number>, "previous_cursor":<number>, "users":[list of
users]}.
A short example to fetch all of a user's followers.
cursor = -1
followers = []
while cursor != 0:
ret = twitter_api.GetFollowers(cursor=cursor)
followers += ret["users"]
cursor = ret["next_cursor"]
Original comment by eoghan.gaffney
on 18 Dec 2009 at 12:35
Attachments:
This is a better version of the patch that uses iterators for GetFriends() and
GetFollowers().
followers = twitter_api.GetFollowers()
print list(f.id for f in followers)
Original comment by sfl...@gmail.com
on 5 Jan 2010 at 11:05
Attachments:
Issue 120 has been merged into this issue.
Original comment by bear42
on 9 Feb 2010 at 6:07
Issue 143 has been merged into this issue.
Original comment by bear42
on 13 Jun 2010 at 11:42
For a first pass I'm changing the parameter to "cursor" so that this will now
function the same but with the new param. I'm hesitant to make the change to
an iterator because that is a functional change to methods behaviour.
After all this OAuth induced panic passes I'll move on to working this into a
proper cursor patch.
Original comment by bear42
on 13 Jun 2010 at 11:58
I have a few suggestions here. Could you clarify what solution you suggest when
you hint at a "proper cursor patch"? Just changing the page parameter to
cursor, or another, more complex change?
On a more generic point, I think that it would make more sense to convert the
methods to generators. It doesnt make much sense to have our users handle that
"cursor" abstraction.
If however this is not a possibility, even including this in a major version
change, then I would advocate for two methods, twitter.iterCursor and
twitter.iterPage, that could wrap respectively cursor- and page-based methods,
to turn them into generators. Obviously, those methods could have handy
parameters such as itemlimit= and pagelimit=, or you-name-it (one limit for the
number of requests, another for the limit of items returned. Result is the
minimum of the two parameters)
While implementation for page-based method does not sound difficult,
implementation for cursors is not straightforward, because you need to tweak
existing methods so they include request metadata in returned results.
For example, instead of returning [User.NewFromJsonDict(x) for x in data], one
would return CursorResult(User.NewFromJsonDict(x) for x in data, cursor) where
CursorResult is a transparent list-like object, containing a _cursor attribute.
I know. When I think at the complexity of the required changes if we want to
ensure backwards-compatibility, my Python zen screams "make it simple, turn the
method into a generator".
Original comment by nicd...@gmail.com
on 14 Jun 2010 at 12:29
Yea, I guess that was very vague - but I was trying to avoid opening a
discussion about what "proper" would be here in the Issues and wanted it to be
on the discussion list.
My main goal for this is to fix some low-hanging bugs, like the 4 changes you
posted and some others, and then on top of that add OAuth.
*Then* we can work on what would be better methods for handling the new
complexities that using cursors requires :)
Original comment by bear42
on 14 Jun 2010 at 12:32
I'm trying to apply this patch but keep getting errors. Is there a preferred
patch I should use to obtain the next_cursor in order to pass it back to the
api.GetFollowers() function?
Thanks.
Original comment by dpao...@gmail.com
on 26 Jul 2010 at 9:32
I patched it manually, I wasn't sure which branch to add the patch to. *gah*
Original comment by dpao...@gmail.com
on 26 Jul 2010 at 10:24
[deleted comment]
Original issue reported on code.google.com by
merrick@gmail.com
on 18 Dec 2009 at 8:32