Flavio Lessa
Flavio Lessa

Reputation: 1

How to reply properly with Tweepy?

I am developing a bot for learning purposes, that replies a meme answer to everyone who types 'good morning' in Portuguese.

However, I cannot seem to reply in the OPs Tweet, only in my feed, using the @ of the OP, which is not as intended. Here's the code:

    import tweepy
    import time
    auth = tweepy.OAuthHandler('xxxx', 'xxxxx')
    auth.set_access_token('xxxxxx', 'xxxxxx')
    
    api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
    user = api.me()
    search = 'bom dia'
    numerotweets = 50
    for tweet in tweepy.Cursor(api.search, search).items(numerotweets):
    try:
            bomdia =  "example, " "@" + tweet.user.screen_name + " example"
            status = api.get_status(tweet)
            api.update_status(status = bomdia, in_reply_status_id = status.id, auto_populate_reply_metadata=True)
    print('bom dia com sucesso')
            tweet.favorite()
            time.sleep(120)
    except tweepy.TweepError as e:
    print(e.reason)
            time.sleep(5)
    break
    except StopIteration:
    break

I´ve tried with in_reply_status_id = tweet.id, but it also did not work. Sometimes I get error 431; sometimes it doesn't find any Tweet.

Upvotes: 0

Views: 66

Answers (1)

Harmon758
Harmon758

Reputation: 5157

The parameter for API.update_status and the POST statuses/update endpoint it uses is in_reply_to_status_id, not in_reply_status_id.

Upvotes: 1

Related Questions