媒体回复推文
Media Reply Tweet
所以我正在尝试创建一个机器人,它用媒体回复每条推文,提到我的机器人。问题是,每当我执行这段代码时:
FILE_NAME = "last_seen_reply.txt"
def read_last_seen(FILE_NAME):
file_read = open(FILE_NAME, 'r')
last_seen_reply_id = int(file_read.read().strip())
file_read.close()
return last_seen_reply_id
def store_last_seen(FILE_NAME, last_seen_reply_id):
file_write = open(FILE_NAME, 'w')
file_write.write(str(last_seen_reply_id))
file_write.close()
return
def reply_to_tweets_with_media():
mentions = api.mentions_timeline(read_last_seen(FILE_NAME), tweet_mode = "extended")
media = api.media_upload(filename = "pinto.png")
mid = media.media_id
for mention in reversed(mentions):
if "@pintobot_" in mention.full_text.lower():
print("Sending reply...")
api.update_status(status = ('@' + mention.user.screen_name +' random text'),in_reply_to_status_id = mention.id)
print("Reply was succesfully sent!")
store_last_seen(FILE_NAME, mention.id)
while True:
reply_to_tweets_with_media()
time.sleep(5)
回复已发送,您实际上可以在推文中看到它,但是当我更改 api.update_status
并包含 media_id、
api.update.status(status = ("@" + mention.user.screen_name + " random text"), in_reply_to_status_id = mention.id, media_ids = [mid])
您可以看到推文的回复数,但看不到回复本身。是 Twitter 的错误,还是我的代码有误?
您的代码很好 - 这似乎是 Twitter 的一个错误,因为我在开始使用 Twitter API 之前很久就遇到过这种情况。请放心,如果您的代码打印出 'Reply was successfully sent!' 并且您可以看到对推文的回复数量,则说明推文已发送。我认为这只是 Twitter 本身的问题,因此无需担心。
如果您在 Twitter 网络应用程序(或 iPhone、Android 上访问您个人资料下的 'Tweets and Replies',无论您想要什么),您应该能够看到如果你想进一步确认,这里有回复。
所以我正在尝试创建一个机器人,它用媒体回复每条推文,提到我的机器人。问题是,每当我执行这段代码时:
FILE_NAME = "last_seen_reply.txt"
def read_last_seen(FILE_NAME):
file_read = open(FILE_NAME, 'r')
last_seen_reply_id = int(file_read.read().strip())
file_read.close()
return last_seen_reply_id
def store_last_seen(FILE_NAME, last_seen_reply_id):
file_write = open(FILE_NAME, 'w')
file_write.write(str(last_seen_reply_id))
file_write.close()
return
def reply_to_tweets_with_media():
mentions = api.mentions_timeline(read_last_seen(FILE_NAME), tweet_mode = "extended")
media = api.media_upload(filename = "pinto.png")
mid = media.media_id
for mention in reversed(mentions):
if "@pintobot_" in mention.full_text.lower():
print("Sending reply...")
api.update_status(status = ('@' + mention.user.screen_name +' random text'),in_reply_to_status_id = mention.id)
print("Reply was succesfully sent!")
store_last_seen(FILE_NAME, mention.id)
while True:
reply_to_tweets_with_media()
time.sleep(5)
回复已发送,您实际上可以在推文中看到它,但是当我更改 api.update_status
并包含 media_id、
api.update.status(status = ("@" + mention.user.screen_name + " random text"), in_reply_to_status_id = mention.id, media_ids = [mid])
您可以看到推文的回复数,但看不到回复本身。是 Twitter 的错误,还是我的代码有误?
您的代码很好 - 这似乎是 Twitter 的一个错误,因为我在开始使用 Twitter API 之前很久就遇到过这种情况。请放心,如果您的代码打印出 'Reply was successfully sent!' 并且您可以看到对推文的回复数量,则说明推文已发送。我认为这只是 Twitter 本身的问题,因此无需担心。
如果您在 Twitter 网络应用程序(或 iPhone、Android 上访问您个人资料下的 'Tweets and Replies',无论您想要什么),您应该能够看到如果你想进一步确认,这里有回复。