python - 在 tweepy 中回复推文

标签 python api twitter tweepy reply

所以我到处搜索,所有呈现给我的解决方案都发布了一条新推文,但实际上并没有回复我收集的推文。我的目标是让脚本回复我检索到的 2 条推文,但由于某种原因没有任何效果,如果有人能帮助解决这个问题,我将不胜感激。

while True:
    for tweet in tweepy.Cursor(api.user_timeline,
                   since='2017-12-24',
                   screen_name='something'
                   ).items(2):
                   try:
                       if not tweet.retweeted:
                               tweet.retweet()
                               m = "Something"
                               t = api.update_status(status=m, in_reply_to_status_id=tweet.id)
                               print("Something, Working...")
                               sleep(10)
                   except tweepy.TweepError as e:
                       print(e.reason)
                       sleep(5)
                       break

                   except StopIteration:
                       break

我尝试了 tweepy 文档中所述的“in_reply_to_status_id”,但它也不起作用,它只是发推文而不是回复。

最佳答案

回复时,在状态前加上@UserName前缀:

while True:
    for tweet in tweepy.Cursor(api.user_timeline,
               since='2017-12-24',
               screen_name='something'
               ).items(2):
               try:
                   if not tweet.retweeted:
                           tweet.retweet()
                           m = "@UserName Something" # <---
                           t = api.update_status(status=m, in_reply_to_status_id=tweet.id)
                           print("Something, Working...")
                           sleep(10)
               except tweepy.TweepError as e:
                   print(e.reason)
                   sleep(5)
                   break

               except StopIteration:
                   break

注意我设置了:

m = "@UserName Something"

带有 @UserName 前缀。

关于python - 在 tweepy 中回复推文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47962277/

相关文章:

Python 作为根目录和/home 文件夹运行脚本

node.js - Mongo运行时错误: Connection pool closed

python - 如何使用 ZenHub API 设置问题管道

twitter - 查找推文位置

javascript - Heroku Twitter API 应用部署

python - 使用 Python 的二维数组(图像)中的像素邻居

python - 方法如何透明地查看函数属性

python - Blender 可以根据文本文件生成场景吗?

css - Facebook 粉丝,设计外观 - 不要工作

java - twitter4j : How to get tweet text with anchor to hash tag and urls