如何使用 API 将 mp4(或其他视频)上传到 Imgur?

How to upload an mp4 (or other video) to Imgur using the API?

我正在使用 Imgur API 将图像上传到相册,作为 Reddit 机器人的一部分。但是,当我尝试上传 MP4 文件时出现错误:"File type invalid (1)"。使用该网站上传完全相同的 MP4 文件就可以了。

我正在使用此端点上传文件:POST https://api.imgur.com/3/image

https://apidocs.imgur.com/#c85c9dfc-7487-4de2-9ecd-66f727cf3139

来自 imgur 帮助网站,位于此处,最后更新于 2 个月前:

https://help.imgur.com/hc/en-us/articles/115000083326-What-files-can-I-upload-What-is-the-size-limit-

File Types

If you need help learning how to upload on Imgur, check out this help article. You can upload any of the following files: JPEG, PNG, GIF, APNG, TIFF, MOV (desktop website only), MP4 (desktop website only)

Imgur doesn't currently support uploads in the following formats: WEBM GIFV

明确地说,目前仅支持直接通过网站手动上传的 MP4。

不幸的是,这意味着 imgur 目前不支持通过除桌面站点以外的任何方法的 MP4 类型。

以上评论不再正确 -- 你确实可以使用 Imgur 上传 MP4 API

import requests

url = "https://api.imgur.com/3/upload"

payload = {'album': 'ALBUMID',
'type': 'file',
'disable_audio': '0'}
files = [
  ('video', open('/path/to/Video.mp4','rb'))
]
headers = {
  'Authorization': 'Bearer BEARERTOKENHERE'
}

response = requests.request("POST", url, headers=headers, data = payload, files = files)

print(response.text.encode('utf8'))

以上对我有用并且上传成功。不过需要注意的是,我还没有想出如何将上传绑定到我的帐户或特定相册中。它似乎忽略了 album_id 字段。换句话说,尽管使用了 Bearer 令牌,它似乎正在导航 API "anonymously"。

我同意上面的评论。现在效果很好。即使您可以未经授权上传视频。仅使用 POST 方法 https://api.imgur.com/3/upload。使用 image 键在正文中传递视频文件。就这些了。

Postman 中的示例