pythontwittertwitterapi-python

Twitter API search not returning full text of tweet


Right now my code is only returning some of the tweets

api = TwitterAPI(consumer_key, consumer_secret, access_key, access_secret)
r = api.request('tweets/search/fullarchive/:prod', {'query' : 'search term',"maxResults": "100",
"fromDate":"201901010000","toDate":"202001310000"})

csvFile = open('output.csv', 'a+')
csvWriter = csv.writer(csvFile)

for tweet in r:
    csvWriter.writerow([tweet['created_at'], tweet['user']['screen_name'], tweet['text'].encode('utf-8') if 'text' in tweet else tweet])

csvFile.close()

Solution

  • If the tweet is an extended tweet use tweet['extended_tweet']['full_text'].

    Not all tweets are extended. So, use a test like this:

    if 'extended_tweet' in tweet: 
        print(tweet['extended_tweet']['full_text'])
    else if 'text' in tweet:
        print(tweet['text'])