缩略图上传YouTube API v3失败 [英] Thumbnail upload YouTube API v3 failing
问题描述
YouTube API v3的记录非常糟糕。我已经多次报告了很多错误,但没有人做出反应。
我仍然需要使用此API上传缩略图。
指南说明:
The YouTube API v3 is horribly documented. I've already reported numerous bugs multiple times but no one reacts. I still have to use this API to upload thumbnails. The guide states:
认证范围:
- https:// www.googleapis.com/auth/youtubepartner
- https://www.googleapis.com/auth/youtube.upload
- https://www.googleapis.com/auth/youtube
- https://www.googleapis.com/auth/youtubepartner
- https://www.googleapis.com/auth/youtube.upload
- https://www.googleapis.com/auth/youtube
参数:
- videoId:string videoId参数指定为其提供自定义视频缩略图的YouTube视频ID。
首先 - 网址错误。它必须是 https://www.googleapis.com/upload/youtube/v3/thumbnails/set
。
现在下面的代码,它使用 Unirest
:
First of all - the url is wrong. It has to be https://www.googleapis.com/upload/youtube/v3/thumbnails/set
.
Now following code, it uses Unirest
:
final HttpResponse<String> response = Unirest.post("https://www.googleapis.com/upload/youtube/v3/thumbnails/set")
.header("Content-Type", "application/octet-stream")
.header("Authorization", accountService.getAuthentication(account).getHeader())
.field("videoId", videoid)
.field("thumbnail", thumbnail)
.asString();
收到的回复:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Required parameter: videoId",
"locationType": "parameter",
"location": "videoId"
}
],
"code": 400,
"message": "Required parameter: videoId"
}
}
这怎么可能? videoId已设置好!
任何人已经玩过这部分API?
How can this be? The videoId is set! Anyone already played with this part of the API?
我可以将请求更改为
Unirest.post("https://www.googleapis.com/upload/youtube/v3/thumbnails/set?videoId=" + videoid)
.header("Content-Type", "application/octet-stream")
.header("Authorization", accountService.getAuthentication(account).getHeader())
.field("mediaUpload", thumbnail)
.asString();
这会给我带来这个错误:
This will throw me this error:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "backendError",
"message": "Backend Error"
}
],
"code": 503,
"message": "Backend Error"
}
}
编辑:
相同请求由Ibrahim Ulukaya发布的URL(参考指南中的原始URL):
Same request with URL posted by Ibrahim Ulukaya (the original url from the reference guide):
{
"error": {
"errors": [
{
"domain": "global",
"reason": "wrongUrlForUpload",
"message": "Uploads must be sent to the upload URL. Re-send this request to https://www.googleapis.com/upload/youtube/v3/thumbnails/set"
}
],
"code": 400,
"message": "Uploads must be sent to the upload URL. Re-send this request to https://www.googleapis.com/upload/youtube/v3/thumbnails/set"
}
}
推荐答案
我们挖掘了这个问题,如果你不想使用这个库,这里是你必须遵循的步骤。
We dug the issue, here are the steps you have to follow if you don't want to use the library.
1 )POST https://www.googleapis.com / upload / youtube / v3 / thumbnails / set?videoId = VIDEO_ID& uploadType = resumable
with empty body
1) POST https://www.googleapis.com/upload/youtube/v3/thumbnails/set?videoId=VIDEO_ID&uploadType=resumable with an empty body
2)取回响应的Location:标题中的URL,以及Content-Type:image / png和主体中缩略图的POST到该URL的POST
2) get back the URL in the Location: header of the response, and POST to that URL with Content-Type: image/png and the thumbnail in the body
这篇关于缩略图上传YouTube API v3失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!