0

I'm building a bot that searches for a word in a tweet and then replies to it.

This is how far I got:

from twython import Twython

CONSUMER_KEY = ""
CONSUMER_SECRET = ""

OAUTH_TOKEN = ""
OAUTH_TOKEN_SECRET = ""

twitter = Twython(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN,    OAUTH_TOKEN_SECRET)

status = twitter.show_status(id="562590793391542272")

message = "hello"

twitter_id = 562590793391542272

How can I get the id of a tweet with a keyword? For example the last tweet with the word "dog" in it?

I have tried streaming/searching and everything, but nothing is working.

Anto
  • 6,806
  • 8
  • 43
  • 65

1 Answers1

1

I am really not certain what you're accomplishing or what you're trying to accomplish with your above code, but I you can accomplish getting the tweet id of the latest tweet with stackoverflow via:

from twython import Twython, TwythonError


app_key = 'your_app_key'
app_secret = 'your_app_secret'
oauth_token = 'your_oauth_tokem'
oauth_token_secret = 'your_oauth_secret'

twitter = Twython(app_key, app_secret, oauth_token, oauth_token_secret)

search_results = twitter.search(count=1, q='stackoverflow')

try:
    for tweet in search_results['statuses']:
        print 'Tweet ID: ', tweet['id']
except TwythonError as e:
    print(e)
mbeacom
  • 1,466
  • 15
  • 25