如何使用Google API将视频上传到youtube.没有图书馆 [英] How to upload video to youtube using google api. Without libraries

查看:60
本文介绍了如何使用Google API将视频上传到youtube.没有图书馆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想为此使用库,我只想向API发送REST请求.这是 API参考,用于上传视频.我没有在文档中的任何地方看到放置视频文件的地方.它应该在标题还是请求正文中?有谁知道该HTTP请求的外观?

I don't want to use libraries for this, I just want to send REST request to the API. Here is API reference for uploading videos. I don't see anywhere in the documentation where to put a video file. Should it be in the header or request body? Does anyone know how this HTTP request should look like?

推荐答案

以下是

Here is the official documentation of the Resumable Upload Protocol, which is used by all of Google's public (open source) libraries.

我个人不建议您使用裸HTTP请求方法来实现可恢复的视频上传.正确地做到这一点非常棘手.但是,如果您不想使用Google的库,则必须吸收此文档并按照需要的方式实施其规范.

I personally would not recommend you to implement resumable video uploading using bare HTTP request methods. That's quite tricky to done it right. But, if you don't want to use Google's libraries, you have to absorb this doc and implement its specifications the way you need it.

还可以一次上传视频(因此不使用上述协议).这将需要在URL上调用 POST 方法:

There's also the possibility to upload videos on one go (thus not using the above mentioned protocol). That would entail calling a POST method on the URL:

https://www.googleapis.com/upload/youtube/v3/videos?uploadType=multipart&part=snippet,状态

您必须在其中编写 multipart/related 内容类型 ,如下所示:

where you'll have to compose a multipart/related content-type as exemplified below:

POST /upload/youtube/v3/videos?uploadType=multipart&part=snippet,status HTTP/1.1
Host: www.googleapis.com
Content-length: 453
Content-type: multipart/related; boundary="===============8268018375852491166=="
Authorization: Bearer [YOUR_VALID_ACCESS_TOKEN]

--===============8268018375852491166==
Content-Type: application/json
MIME-Version: 1.0

{
  "snippet": {
    "title": "test video",
    "description": "just some test video",
    "categoryId": "22"
  },
  "status": {
    "privacyStatus": "private",
    "embeddable": false,
    "license": "youtube"
  }
}

--===============8268018375852491166==
Content-Type: video/mp4
MIME-Version: 1.0
Content-Transfer-Encoding: binary

TEST

--===============8268018375852491166==--

您可以作为自己的代码的灵感之源此Python3脚本我实现了一个前一阵子.该脚本以指定视频元数据的JSON对象作为输入要上传的视频文件本身,并生成 multipart/related 文件和关联的 Content-Type HTTP标头,这些标头可能会被即兴的 curl 命令.(向我的脚本发送-help 以获得简短的帮助信息.)

You could use as spring of inspiration for your own code this Python3 script I implemented a while ago. The script takes as input an JSON object specifying the metadata of the video to be uploaded and the video file itself and generates the multipart/related file and the associated Content-Type HTTP header that could well be used by an immendiate curl command. (Issue my script with --help for brief helping info.)

请注意,我的脚本基于Google自己的开源代码,特别是基于 Google的Python API客户端库的一部分.

Note that my script is based on Google's own open source code, specifically on discovery.py. This latter script is part of Google's APIs Client Library for Python.

这篇关于如何使用Google API将视频上传到youtube.没有图书馆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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