Allow int or str IDs as streaming arguments #830

Open
wants to merge 1 commit into
from

Projects

None yet

2 participants

@fitnr
Contributor
fitnr commented Jan 3, 2017

Fix for #829. The str.join method raises a ValueError for ints.

@dannguyen

Thanks @fitnr. I'm only just getting acquainted with using the Streaming API vs Tweepy so I know there are other dependencies and conventions to consider, so this is for future discussion: it might be worthwhile to throw a warning when a user passes in a string.

Right now, the behavior -- and I'm assuming this is unintended -- is to silently fail when a string value is passed into the follow argument/parameter. But because the follow parameter, according to Twitter's API spec, only accepts user IDs:

https://dev.twitter.com/streaming/overview/request-parameters#follow

A comma-separated list of user IDs, indicating the users whose Tweets should be delivered on the stream.

In other words, it is never the case that the Twitter API will accept follow=["ev"]. Shouldn't the user be warned that what they are trying will always turn up nothing?

In fact, I'd almost argue that it's better for filter to throw an error. Consider the uncommon case in which a user's screen name is entirely made up of numbers. Such as Twitter user @101, whose user_id is actually 3781411.

What behavior should the user expect with the following invocation?

   mystream.filter(follow=['101'])

Forcing the API of filter to accept only integers provides at least an implication of what the follow parameter is limited to:

   mystream.filter(follow=[101])
@fitnr
Contributor
fitnr commented Jan 3, 2017

I don't think changing signature of the stream.filter function to now throw warnings or errors when sequences of strs are passed is a friendly choice. Since a Twitter ID may, for good reason, be stored either as an int or a str, I say let the function accept either, and throw an error if Twitter complains. Designing guard rails or trying to police a certain kind of behvaior seems unnecessary in a library that tracks a complicated and ever-changing API.

To answer your question about this:

mystream.filter(follow=['101'])

I would expect that will produce a stream that follows the user with user_id == 101. I would base that on reading the API spec on streaming. It should also be documented in the Tweepy docs (which are currently a little garbled on the streaming API, but that's another issue).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment