作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
YouTube API v3 的文档非常糟糕。我已经多次报告过许多错误,但没有人使用react。我仍然必须使用此 API 来上传缩略图。该指南指出:
POST https://www.googleapis.com/youtube/v3/thumbnails/set
Auth scopes:
- https://www.googleapis.com/auth/youtubepartner
- https://www.googleapis.com/auth/youtube.upload
- https://www.googleapis.com/auth/youtube
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/
我是一名优秀的程序员,十分优秀!