skip to Main Content

What I want is to search tweets that have multiple words I choose on twitter with python.
The official doc dose not say anything but it seems that the search method only takes 1 query.

source code

import tweepy
CK=
CS=
AT=
AS=
auth = tweepy.OAuthHandler(CK, CS)
auth.set_access_token(AT, AS)
api = tweepy.API(auth)
for status in api.search(q='word',count=100,): # I want to set multiple words in q but when I do.
    print(status.user.id)
    print(status.user.screen_name)
    print(status.user.name)
    print(status.text)
    print(status.created_at)

What I have tried is below it didn’t get any error but it searched only with the last word in the query in this case, the results were only tweets with the word "Python" it did not get tweets with both words.

for status in api.search(q='Java' and 'Python',count=100,)

Official doc
https://developer.twitter.com/en/docs/twitter-api/v1/tweets/search/api-reference/get-search-tweets

So my questions is that is it possible to set multiple words in query.
Is the way I wrote is simply wrong?
If so, please let me know.
If it can’t set multiple words, I would appreciate if you could share simple python code that works for what I want to do.

Thank you in advance.

2

Answers


  1. Use:

    for status in api.search(q='Java Python', count=100)
    

    From the Search Tweets: Standard v1.1 section Standard search operators:

    watching now    - containing both “watching” and “now”. This is the default operator.
    
    Login or Signup to reply.
  2. As explained by Vlad Siv, just put each word you wish to look for in the speech marks for the query param. This should in turn look for tweets containing these words.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search