Update title and description using YouTube v3 API?

2020-03-26 05:08发布

I successfully uploaded a video to YouTube using YouTube Data API v3. No third party libraries were used. Now I want to update the title and description of an uploaded video, but this seems impossible!

This should be a no-brainer, but YouTube refuses to accept this simple query:

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"

Even though I'm dead sure that the video does exist YouTube server responds with this:

{
 "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."
 }
}

Can somebody please show me the low-level commands (cannot use third party library) to successfully update the title and description of an uploaded video? Preferably using curl.

UPDATE:

I am able to delete the file using the delete API. Hence, the ID is indeed correct.

2条回答
爷的心禁止访问
2楼-- · 2020-03-26 05:45

Not sure why, but if I include the entire json response from the actual upload, it works. That is, to update the description I do the following:

  1. Upload video.
  2. Wait for response.
  3. Parse json response and replace description text.
  4. Update video with new json.

Hence, updating using a stripped down json does not seem to work.

查看更多
叼着烟拽天下
3楼-- · 2020-03-26 05:51

It looks like you might be missing the "kind" value.

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"
查看更多
登录 后发表回答