【问题标题】:How to reply properly with Tweepy?如何用 Tweepy 正确回复?
【发布时间】:2021-09-08 05:36:16
【问题描述】:

我正在开发一个用于学习目的的机器人,它会向用葡萄牙语输入“早上好”的每个人回复一个模因答案。

但是,我似乎无法在 OP 推文中回复,只能在我的提要中使用 OP 的 @ 进行回复,这与预期不符。代码如下:

    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

我试过in_reply_status_id = tweet.id,但也没有用。有时我会收到错误 431;有时它找不到任何推文。

【问题讨论】:

  • 打印bombia 以确保它有正确的结果。另外,为什么status = api.get_status(tweet) 只是为了得到它的id?您可以从tweet 对象中获取它并将其用作in_reply_status_id=tweet.id。
  • 我也试过了,但它只出现在我的提要上,它不会在用户的推文中回复。

标签: python api twitter tweepy


【解决方案1】:

API.update_status 及其使用的POST statuses/update 端点的参数是in_reply_to_status_id,而不是in_reply_status_id。

【讨论】:

    猜你喜欢
    • 2012-12-15
    • 1970-01-01
    • 1970-01-01
    • 2021-06-01
    • 2012-03-08
    • 2016-09-03
    • 2021-01-03
    • 1970-01-01
    • 2018-05-19
    相关资源
    最近更新 更多