使用 tweepy 发布 mp4 文件 [英] Tweet mp4 files with tweepy

查看:37
本文介绍了使用 tweepy 发布 mp4 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我想将使用 ffmpeg 生成的 mp4 文件发送到 Twitter.然而,似乎没有真正的本地方法可以用官方的 tweepy 来做到这一点.当尝试使用 api.update_with_media(filename, message) 方法时,你会得到一个错误,不支持的文件 'video/mp4'

Hey I'd like to tweet a mp4 file generated using ffmpeg to twitter. However it seems that there's no real native way to do this with the official tweepy. When tried with the api.update_with_media(filename, message) method, you'll get an error, unsupported file 'video/mp4'

所以首先我看到了一个讨论,这个 github 项目链接:Github 链接

So first I saw a discussion where this github project was linked: Github link

但在测试代码后,应用在第一个 INIT 阶段后崩溃.

But after testing out the code, the app crashs after the first INIT phase.

所以接下来我看到了这个:Github pull请求线程

So next I saw this: Github pull request thread

在那个帖子上宣布有一个代码来推特视频,但它尚未正式合并,braian87b 用上传视频的代码制作了一个 tweepy 分支.

And on that thread it was announced that there is a code to tweet video but it hasn't officialy been merged yet, and braian87b made a fork of tweepy with the code to upload videos.

但是我不知道如何安装和使用 tweepy 的分支以及如何实际使用代码来发布视频.Braian87b 以此作为示例代码:

However I have no idea how to install and use a fork of tweepy and how to actually use the code to tweet a video. Braian87b used this as an example code:

upload_result = api.media_upload('/home/user/video.mp4')
api.update_status(status="test tweet", media_ids=[upload_result.media_id_string])

任何帮助将不胜感激!:)

Any help would be apreciated! :)

推荐答案

最后我理解了.制作我自己的 fork(因为提供的一个 braian87b 与最新版本的 pip 不兼容,这是我用来安装它的),我能够使用 pip 安装 fork tweepy

In the end I managed to understand it. Making a fork of my own (as the one braian87b provided was incompatible with the latest version of pip, which is what I used to install it), I was able to install the forked tweepy by using pip

pip install git+https://github.com/Spyder-exe/tweepy.git

然后braian87b提供的代码最终非常好!所以使用这个代码

and then the code that braian87b provided was in the end perectly good! So using this code

upload_result = api.media_upload('/home/user/video.mp4')
api.update_status(status="test tweet", media_ids=[upload_result.media_id_string])

并确保将reply_to_status_id 标签置于 media_ids 标签之前,我能够将视频上传到推特,而只有轻微的烦恼.

And making sure to put the reply_to_status_id tag before the media_ids tag, I was able to upload videos to twitter with only minor annoyances.

这篇关于使用 tweepy 发布 mp4 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆