如何解决我如何发布我刚刚保存的带有 tweepy 的图片?
我正在做一个 twitter 机器人来回复提到他的人,我需要保存一个文件,而不是推特这个文件,但我每次都收到这个错误
def reply():
tweets = api.mentions_timeline(read_last_seen(FILE_NAME),tweet_mode='extended',include_entities=True)
for tweet in reversed(tweets):
if 'invertbot1' in tweet.full_text.lower():
image = Image.open('cat2.jpg')
draw = ImageDraw.Draw(image)
font = ImageFont.truetype('arial.ttf',size=17)
text = tweet.full_text
textwrapped = textwrap.wrap(text,width=21)
color = 'rgb(0,0)' # black color
draw.multiline_text((85,30),'\n'.join(textwrapped),font=font,fill="#aa0000")
image.save('cat1.jpg')
print(str(tweet.id) + ' - ' + tweet.full_text)
store_last_seen(FILE_NAME,tweet.id)
img = 'cat1.jpg'
import time
api.update_status(img,"@" + tweet.user.screen_name + " Pronto",in_reply_to_status_id = tweet.id)
os.remove('cat1.jpg')
我得到的错误是
tweepy.error.TweepError: Multiple values for parameter in_reply_to_status_id supplied!
解决方法
上传媒体后,图像作为数组在 media_ids
参数中传递:
# upload media
media = api.media_upload(filename='cat1.jpg')
# reply
api.update_status(status='my reply',in_reply_to_status_id=tweet.id,media_ids=[media.media_id])
注意回复 Tweet 的作者必须在状态文本中提及,否则 in_reply_to_status_id
将被忽略。查看更新状态的documentation
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。