skip to Main Content

How can I search for more than one keyword while fetching tweets using twitter streaming API in python 3.6?
I want to fetch old tweets from jan 01 2017 to jan 31 2017. But,using the following code, I can only fetch tweets that contain only one keyword! This is my code:

import got3

max_tweets = 3
tweetCriteria = got3.manager.TweetCriteria().setSince("2017-01-01").setUntil("2017-01-31").setQuerySearch("Mexico Earthquake").setMaxTweets(max_tweets)

for i in range(max_tweets):
    tweet = got3.manager.TweetManager.getTweets(tweetCriteria)[i]
    print(tweet.id)
    print(tweet.username)
    print(tweet.text)
    print(tweet.date)

In the above code, “Mexico Earthquake” is my keyword. I want to include “Magnitude 7.5” as the keyword also. I try to give a list as an argument to setQuerySearch,but it shows an error: “only str is accepted as an argument,not list”
How can I modify my code?

2

Answers


  1. You doesn’t get old tweet by using twitter API because it get tweets in last week.
    You hove to use search engine of twitter.
    GetOldTweets-python is a program that get old tweets with any keywords you want.

    Login or Signup to reply.
  2. i found it worked best with separate query classes and set query searches.

    text_query = ','
    hashtag_query = ','
    mention_query = ','
    
    .setQuerySearch(text_query)
    .setQuerySearch(hashtag_query)
    .setQuerySearch(mention_query)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search