Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue using Pagination reverse flag on search_recent_tweets #1926

Closed
dtaivpp opened this issue Jul 27, 2022 · 1 comment
Closed

Issue using Pagination reverse flag on search_recent_tweets #1926

dtaivpp opened this issue Jul 27, 2022 · 1 comment
Labels
Need Follow-Up This needs to be followed up on to be actionable No Reproduction This is not reproducible Stale This is inactive, outdated, too old, or no longer applicable

Comments

@dtaivpp
Copy link

dtaivpp commented Jul 27, 2022

Hey all, I am not sure if I am missing something but when I am running pagination with the reversed flag the number of results I receive is dramatically different than when I run it without the flag.

cl = tweepy.Client(bearer_token=token)
tweets = tweepy.Paginator(cl.search_recent_tweets,  
                                "OpenSearch",
                                tweet_fields=['id', 'author_id', 'text', 'lang', 'public_metrics', 'created_at', 'entities'],
                                expansions=['author_id', 'referenced_tweets.id'], 
                                user_fields=['username'],
                                max_results=40,
                                since_id=None)

all_tweets = []
for tweet_page in tweets:
    for tweet in tweet_page.data
        all_tweets.append(normalize_tweet(tweet))

When I run the above with reversed = True at the moment I get exactly 80 results (2 iterations). Without the reversed flag I receive ~460 results.

@Harmon758
Copy link
Member

If you're referring to the reverse parameter for PaginationIterator, that's used for paginating backwards. It would be expected that passing it as True to Paginator without a pagination token would only return a single iteration/response, since that would be the first page with nothing to paginate backwards to, and that is the behavior I'm seeing:

>>> responses = tweepy.Paginator(
...     client.search_recent_tweets,
...     "OpenSearch",
...     tweet_fields=[
...         'id', 'author_id', 'text', 'lang', 'public_metrics', 'created_at',
...         'entities'
...     ],
...     expansions=['author_id', 'referenced_tweets.id'],
...     user_fields=['username'],
...     max_results=40,
...     since_id=None,
...     reverse=True
... )
>>> len(list(responses))
1

I'm encountering the same expected behavior when using the Python built-in reversed function:

>>> responses = tweepy.Paginator(
...     client.search_recent_tweets,
...     "OpenSearch",
...     tweet_fields=[
...         'id', 'author_id', 'text', 'lang', 'public_metrics', 'created_at',
...         'entities'
...     ],
...     expansions=['author_id', 'referenced_tweets.id'],
...     user_fields=['username'],
...     max_results=40,
...     since_id=None
... )
>>> len(list(reversed(responses)))
1

I'm unable to reproduce 2 iterations/responses being returned.

Otherwise, I'm not sure what "reversed flag" you're referring to, as there is no reversed parameter anywhere in Tweepy, and I'm pretty sure there's not a reversed parameter for any Twitter API endpoints either (and definitely not for the recent search endpoint).

Do you have a reproducible example (MCVE/SSCCE) of what exactly you're trying and encountering?

@Harmon758 Harmon758 added Need Follow-Up This needs to be followed up on to be actionable No Reproduction This is not reproducible labels Oct 27, 2022
@Harmon758 Harmon758 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 11, 2022
@Harmon758 Harmon758 added the Stale This is inactive, outdated, too old, or no longer applicable label Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Need Follow-Up This needs to be followed up on to be actionable No Reproduction This is not reproducible Stale This is inactive, outdated, too old, or no longer applicable
Projects
None yet
Development

No branches or pull requests

2 participants