gpt4 book ai didi

java - 缩略图上传 YouTube API v3 失败

转载 作者:可可西里 更新时间:2023-11-01 16:28:37 25 4
gpt4 key购买 nike

YouTube API v3 的文档非常糟糕。我已经多次报告过许多错误,但没有人使用react。我仍然必须使用此 API 来上传缩略图。该指南指出:

POST https://www.googleapis.com/youtube/v3/thumbnails/set

Auth scopes:

Parameters:

  • videoId: string The videoId parameter specifies a YouTube video ID for which the custom video thumbnail is being provided.

首先 - 网址错误。它必须是 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"
}
}

最佳答案

我们解决了这个问题,如果您不想使用该库,则必须遵循以下步骤。

1) 发布 https://www.googleapis.com/upload/youtube/v3/thumbnails/set?videoId=VIDEO_ID&uploadType=resumable空空如也

2) 取回 Location: 响应头中的 URL,并使用 Content-Type: image/png 和正文中的缩略图 POST 到该 URL

关于java - 缩略图上传 YouTube API v3 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18382388/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com