How to return over 100 Twitter search results using Twython?

Twitter only returns 100 tweets per “page” when returning search results to the API. They provide max_idand since_idin the return search_metadata, which can be used as parameters for receiving early / late tweets.

The Twython 3.1.2 documentation suggests that this template is the “old way” to search:

results = twitter.search(q="xbox",count=423,max_id=421482533256044543)
for tweet in results['statuses']:
    ... do something

and that is a new way :

results = twitter.cursor(t.search,q='xbox',count=375)
for tweet in results:
    ... do something

When I do the latter, it seems to endlessly iterate over the same search results. I try to push them to a CSV file, but it pushes a ton of duplicates.

What is the right way to search for a large number of tweets using Twython and repeat many unique results?

: , (for tweet in results:), , . - ... https://github.com/ryanmcgrath/twython/issues/300

+4
4

, , , max_id. 100 Terence ( , user_timeline 200 - ) max_id id ( max_id ). :

'''
Get all tweets from a given user.
Batch size of 200 is the max for user_timeline.
'''
from twython import Twython, TwythonError
tweets = []
# Requires Authentication as of Twitter API v1.1
twitter = Twython(PUT YOUR TWITTER KEYS HERE!)
try:
    user_timeline = twitter.get_user_timeline(screen_name='eugenebann',count=200)
except TwythonError as e:
    print e
print len(user_timeline)
for tweet in user_timeline:
    # Add whatever you want from the tweet, here we just add the text
    tweets.append(tweet['text'])
# Count could be less than 200, see:
# https://dev.twitter.com/discussions/7513
while len(user_timeline) != 0: 
    try:
        user_timeline = twitter.get_user_timeline(screen_name='eugenebann',count=200,max_id=user_timeline[len(user_timeline)-1]['id']-1)
    except TwythonError as e:
        print e
    print len(user_timeline)
    for tweet in user_timeline:
        # Add whatever you want from the tweet, here we just add the text
        tweets.append(tweet['text'])
# Number of tweets the user has made
print len(tweets)
+1

API Twitter .

, 100

0

python. , , N, , .

, api: https://dev.twitter.com/docs/streaming-apis oauth2.

api Twitter mongodb

python-twitter streaming api support/example

Disclaimer: I really have not tried this

0
source

As a solution to the problem of returning 100 tweets for a search query using Twython, here is a link showing how this can be done using the "old method":

Twython API with next_results

0
source

All Articles