【问题标题】:replying to a tweet in tweepy用 tweepy 回复推文
【发布时间】:2020-03-11 23:31:03
【问题描述】:

我的代码存在一个问题,无论我尝试什么,每次我回复推文时,它都会作为定期状态更新发布在我的时间线上。

这是一个sn-p的代码

class StreamListener(tweepy.StreamListener):
 def on_status(self, status):
    tweetid = status.id
    tweetnouser = status.text.replace("@CarlWheezerBot", "")
    username = '@'+status.user.screen_name


    user_tweet = gTTS(text=tweetnouser, lang='en', slow=False)

    # Saving the converted audio

    user_tweet.save("useraudio/text2speech.mp3")

    # importing the audio and getting the audio all mashed up
    text2speech = AudioFileClip("useraudio/text2speech.mp3")
    videoclip = VideoFileClip("original_video/original_cut.mp4")
    editedAudio = videoclip.audio

    # splicing the original audio with the text2speech
    compiledAudio = CompositeAudioClip([editedAudio.set_duration(3.8), text2speech.set_start(3.8)])
    videoclip.audio = compiledAudio

    # saving the completed video fie
    videoclip.write_videofile("user_video/edited.mp4", audio_codec='aac')

    upload_result = api.media_upload("user_video/edited.mp4")
    api.update_status( status='@CarlWheezerBot',in_reply_to_status_id=[tweetid], media_ids=[upload_result.media_id_string], auto_populate_reply_metadata=True)

我也试过没有任何状态,以及使用status.id_str。似乎没有任何效果。,我也没有元数据参数就完成了。我逐字逐句地按照文档进行操作。

【问题讨论】:

    标签: python twitter tweepy


    【解决方案1】:

    好的。供以后阅读本文的每个人使用

    使用这个in_reply_to_status_id=tweetid

    不要使用方括号。现在一切正常

    【讨论】:

    • "方括号" 表示一个包含一个元素 [tweetid] 的数组。 tweetid 实际上是一个整数
    【解决方案2】:

    在玩弄它的同时,我还注意到您还应该提及您正在回复的推文的作者,特别是如果您正在回复现有回复,因为它仍会将其发布为状态更新。文档中的行:

    in_reply_to_status_id - 更新回复的现有状态的 ID。注意:除非状态文本中提到了此参数引用的推文的作者,否则此参数将被忽略。因此,您必须在更新中包含@username,其中用户名是引用推文的作者。

    【讨论】:

      猜你喜欢
      • 2012-03-08
      • 1970-01-01
      • 2016-11-04
      • 2021-07-25
      • 2016-10-20
      • 1970-01-01
      • 2014-10-24
      • 2016-09-20
      • 2018-10-20
      相关资源
      最近更新 更多