Here is the official documentation of the Resumable Upload Protocol, which is used by all of Google's public (open source) libraries.
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.
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,status
,
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==--
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.)
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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…