update publishAt date of a youtube video

2019-09-18 15:36发布

I'm trying to set the publishAt date of a youtube video to 5 minutes from now:

Request

GET https://www.googleapis.com/youtube/v3/videos?part=status&id=_VIDEOID_&key=_KEY_

Authorization:  Bearer xxxxx
X-JavaScript-User-Agent:  Google APIs Explorer

Response

200 OK

{
 - snip-
 "items": [
  {

   "kind": "youtube#video",
   "etag": "\"F9iA7pnxqNgrkOutjQAa9F2k8HY/ctlUM3pGyXYfW6_IYy2nlhviZZ4\"",
   "id": "_VIDEOID_",
   "status": {
    "uploadStatus": "processed",
    "privacyStatus": "private",
    "license": "youtube",
    "embeddable": true,
    "publicStatsViewable": true
   }
  }
 ]
}

So fine, I get the video info, then I try to set the video's publishAt value

Request

PUT https://www.googleapis.com/youtube/v3/videos?part=status&key=_KEY_

Content-Type:  application/json
Authorization:  Bearer xxxx
X-JavaScript-User-Agent:  Google APIs Explorer

{
 "status": {
   "embeddable": true,
   "license": "youtube",
   "privacyStatus": "private",
   "publicStatsViewable": true,
   "publishAt": "2015-01-21T11:20:27.751+00:00"
 },
 "id": "_VIDEOID_"
}

Response

400 Bad Request

{
 "error": {
  "errors": [
   {
    "domain": "youtube.video",
    "reason": "invalidRequest",
    "message": "Bad Request"
   }
  ],
  "code": 400,
  "message": "Bad Request"
 }
}

Any clues?

I can't see what I'm doing wrong. The documentation says that i should be able to set the publishAt value. I can't work this one out!

I've tested this using https://developers.google.com/youtube/v3/docs/videos/update and the C# API with the same response.

标签: youtube-api
2条回答
Rolldiameter
2楼-- · 2019-09-18 15:52

The problem was that I was setting the publishAt too close to the current time (5 minutes.) 60 minutes worked.

In my opinion this should be better documented and the UPDATE call should return an error similar to the INSERT (badRequest (400) invalidPublishAt)

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-09-18 16:05

To change a field in upload method, you have to put all other fields you get, otherwise the update method will think you are trying to empty them.

In your case, you should include "license" and "publicStatsViewable" in your PUT request just as you get them from your "GET" request.

查看更多
登录 后发表回答