我正在使用 youtube data v3 api 通过我的网站上传 mp4 视频,http post 请求如下所示:
access_token = request.session['access_token']
url = "https://www.googleapis.com/upload/youtube/v3/videos?part=snippet"
payload = {
'snippet':{
"categoryId": "22",
"description": "Description of uploaded video.",
"title": "Test video upload."
}
}
files = [
('media_body', request.FILES['media_body'])
]
headers = {
'Content-Type': 'video/mp4',
'Authorization': 'Bearer '+access_token,
}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text.encode('utf8'))
context = {
'r': response
}
return render_to_response('dashboard/manage_content/youtube.html', context)
这是我得到的回复:
{ "kind": "youtube#video", "etag": "yS7DhsHOhsDM-vXZiGUmLXcKST0", "id": "dII224dYC2o", "snippet": { "publishedAt": "2020-07-03T12:11:43Z", "channelId": "UCmv2Sec30iBc13b7ntf93Ow", "title": "unknown", "description": "", "thumbnails": { "default": { "url": "https://i.ytimg.com/vi/dII224dYC2o/default.jpg", "width": 120, "height": 90 }, "medium": { "url": "https://i.ytimg.com/vi/dII224dYC2o/mqdefault.jpg", "width": 320, "height": 180 }, "high": { "url": "https://i.ytimg.com/vi/dII224dYC2o/hqdefault.jpg", "width": 480, "height": 360 } }, "channelTitle": "Nikhil Dhoot", "categoryId": "20", "liveBroadcastContent": "none", "localized": { "title": "unknown", "description": "" } } }
但在视频选项卡上,我收到错误:处理已放弃 无法处理视频。 视频响应成功消息意味着之前的所有身份验证过程都已成功。但是,如果需要,我也可以编辑和共享该代码。
最佳答案
将视频上传到 YouTube 的过程分为两步:
调用
Videos.insert
API 端点,向其发布正确的 JSON text describing你的视频。API 调用后,从 API 端点响应获取实际上传视频内容的位置。然后进行实际的内容上传操作。
请仔细检查 source code Google 在 YouTube 上公开上传视频。您将了解我上面概述的算法的所有具体细节。
如果您想深入了解函数 resumable_upload
中的调用 request.next_chunk()
的工作原理,请阅读相关部分 - 方法 HttpRequest.next_chunk
-- 在文件 http.py
中Google 的 Python API 客户端库。
关于django - 放弃处理 无法处理视频 - Youtube API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62715687/