如何使用 google api 将视频上传到 youtube。没有图书馆
How to upload video to youtube using google api. Without libraries
我不想为此使用库,我只想向 API 发送 REST 请求。这里是API reference上传视频。我没有在文档中的任何地方看到放置视频文件的位置。它应该在 header 中还是在请求 body 中?有谁知道这个 HTTP 请求应该是什么样子的?
这是 Resumable Upload Protocol 的官方文档,Google 的所有 public(开源)库都使用它。
我个人不建议您使用纯 HTTP 请求方法实现可续传视频上传。要做到这一点非常棘手。但是,如果你不想使用 Google 的库,你必须吸收这个文档并按照你需要的方式实现它的规范。
也可以一次性上传视频(因此不使用上述协议)。这将需要在 URL:
上调用 POST
方法
https://www.googleapis.com/upload/youtube/v3/videos?uploadType=multipart&part=snippet,status
,
您必须在其中编写 multipart/related
content-type
,如下所示:
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==--
您可以将要上传的视频和视频文件本身的代码 this Python3 script I implemented a while ago. The script takes as input an JSON object specifying the metadata 用作 spring 的灵感,并生成 multipart/related
文件和关联的 Content-Type
HTTP header 可以被即时 curl
命令使用。 (使用 --help
发布我的脚本以获得简短的帮助信息。)
注意我的脚本是基于Google自己的开源代码,具体是在discovery.py
. This latter script is part of Google's APIs Client Library for Python.
我不想为此使用库,我只想向 API 发送 REST 请求。这里是API reference上传视频。我没有在文档中的任何地方看到放置视频文件的位置。它应该在 header 中还是在请求 body 中?有谁知道这个 HTTP 请求应该是什么样子的?
这是 Resumable Upload Protocol 的官方文档,Google 的所有 public(开源)库都使用它。
我个人不建议您使用纯 HTTP 请求方法实现可续传视频上传。要做到这一点非常棘手。但是,如果你不想使用 Google 的库,你必须吸收这个文档并按照你需要的方式实现它的规范。
也可以一次性上传视频(因此不使用上述协议)。这将需要在 URL:
上调用POST
方法
https://www.googleapis.com/upload/youtube/v3/videos?uploadType=multipart&part=snippet,status
,
您必须在其中编写 multipart/related
content-type
,如下所示:
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==--
您可以将要上传的视频和视频文件本身的代码 this Python3 script I implemented a while ago. The script takes as input an JSON object specifying the metadata 用作 spring 的灵感,并生成 multipart/related
文件和关联的 Content-Type
HTTP header 可以被即时 curl
命令使用。 (使用 --help
发布我的脚本以获得简短的帮助信息。)
注意我的脚本是基于Google自己的开源代码,具体是在discovery.py
. This latter script is part of Google's APIs Client Library for Python.