使用 YouTube v3 API 更新标题和描述?

l33*_*33t 5 curl youtube-api

我使用YouTube Data API v3成功将视频上传到 YouTube 。没有使用第三方库。现在我想更新上传视频的标题和描述,但这似乎不可能!

这应该很简单,但 YouTube 拒绝接受这个简单的查询:

curl --insecure -v -i -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer ACCESS_TOKEN_FROM_GOOGLE_HERE" -d '{"id":"YOUTUBE_VIDEO_ID_HERE","snippet":{"title":"My title","description":"My description","categoryId":"22"}}' "https://www.googleapis.com/youtube/v3/videos?part=snippet"

即使我很确定该视频确实存在,YouTube 服务器也会对此做出响应:

{
 "error": {
  "errors": [
   {
    "domain": "youtube.video",
    "reason": "videoNotFound",
    "message": "The video that you are trying to update cannot be found. Check t
he value of the \u003ccode\u003eid\u003c/code\u003e field in the request body to
 ensure that it is correct.",
    "locationType": "other",
    "location": "body.id"
   }
  ],
  "code": 404,
  "message": "The video that you are trying to update cannot be found. Check the
 value of the \u003ccode\u003eid\u003c/code\u003e field in the request body to e
nsure that it is correct."
 }
}
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我低级命令(不能使用第三方库)来成功更新上传视频的标题和描述吗?最好使用curl

更新:

我可以使用delete API删除文件。因此,ID确实是正确的。

van*_*eem 5

看起来您可能缺少“种类”值。

curl --insecure -v -i -X PUT -H "Content-Type: application/json" -H "Authorization:  Bearer ACCESS_TOKEN_FROM_GOOGLE_HERE" -d '{"id":"YOUTUBE_VIDEO_ID_HERE","kind":"youtube#video","snippet":{"title":"My title","description":"My description","categoryId":"22"}}' "https://www.googleapis.com/youtube/v3/videos?part=snippet"
Run Code Online (Sandbox Code Playgroud)


l33*_*33t -1

json不知道为什么,但如果我包含实际上传的完整响应,它就会起作用。也就是说,为了更新描述,我执行以下操作:

  1. 上传视频。
  2. 等待回复。
  3. 解析 json 响应并替换描述文本。
  4. 使用新的 json 更新视频。

因此,使用精简的 json 进行更新似乎不起作用。