Evie
Evie

Reputation: 1

Search for a keyword in a user's tweets

Whenever I run the code below, it gives me the most recent 10 tweets from @Spongebob, instead of giving me the tweets that include "Bikini Bottom" from the last 10 tweets. How do I make it conditional to the keyword?

user = api.get_user('SpongeBob')
public_tweets = api.user_timeline("Bikini Bottom", count=10, screen_name = "SpongeBob")
for tweet in public_tweets:
    print(tweet.text)

Upvotes: 0

Views: 630

Answers (1)

Terence Eden
Terence Eden

Reputation: 14334

You need to use the Twitter Search API, with the correct search operators.

In this case, you want to search for the string "bikini bottom from:spongebob"

With Tweepy, this will be:

public_tweets = api.search("bikini bottom from:spongebob")

Upvotes: 1

Related Questions