skip to Main Content

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()

2

Answers


  1. 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'])
    
    Login or Signup to reply.
  2. This worked for me!

        tweets = api.search_tweets(q=search_term, tweet_mode='extended', count=tweet_amount)
    
    for tweet in tweets:
        # check if the tweet is a retweet
        if tweet.full_text.startswith('RT @'):
            # if the tweet is a retweet, use the retweeted_status attribute
            full_text = tweet.retweeted_status.full_text
        else:
            full_text = tweet.full_text
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search