YouTube API v3 的文档非常糟糕。我已经多次报告了许多错误,但没有人做出反应。我仍然必须使用这个 API 来上传缩略图。该指南指出:
发布https://www.googleapis.com/youtube/v3/thumbnails/set
授权范围:
- 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
:
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 了吗?
我可以将请求更改为
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();
这会给我这个错误:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "backendError",
"message": "Backend Error"
}
],
"code": 503,
"message": "Backend Error"
}
}
编辑:与 Ibrahim Ulukaya 发布的 URL 相同的请求(参考指南中的原始 url):
{
"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"
}
}