Skip to content

Allow int or str IDs as streaming arguments - #830

Merged
Harmon758 merged 3 commits into
tweepy:masterfrom
fitnr:follow_int
Feb 21, 2021
Merged

Allow int or str IDs as streaming arguments#830
Harmon758 merged 3 commits into
tweepy:masterfrom
fitnr:follow_int

Conversation

@fitnr

@fitnr fitnr commented Jan 3, 2017

Copy link
Copy Markdown
Contributor

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

@dannguyen

Copy link
Copy Markdown

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

fitnr commented Jan 3, 2017

Copy link
Copy Markdown
Contributor Author

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 behavior 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).

@Harmon758 Harmon758 added the Improvement This is regarding an improvement to an existing feature label Jun 1, 2019
@Harmon758
Harmon758 force-pushed the master branch 5 times, most recently from cf54e31 to d538993 Compare August 27, 2019 04:24
Comment thread tweepy/streaming.py Outdated
Comment thread tweepy/streaming.py Outdated
@Harmon758 Harmon758 added the Need Follow-Up This needs to be followed up on to be actionable label Dec 30, 2020
@Harmon758 Harmon758 added this to the 4.0 milestone Dec 30, 2020
@Harmon758 Harmon758 removed the Need Follow-Up This needs to be followed up on to be actionable label Feb 21, 2021
@Harmon758
Harmon758 merged commit 5630d6b into tweepy:master Feb 21, 2021
@fitnr
fitnr deleted the follow_int branch May 20, 2022 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Improvement This is regarding an improvement to an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StreamListener.filter(): follow argument doesn't accept integers for user ids

3 participants