如何使用API​​ v3在YouTube上更新视频

时间:2012-11-20 09:09:02

标签: youtube-api

我正在尝试使用“试试吧!”在本页面: https://developers.google.com/youtube/v3/docs/videos/update

但是我收到错误请求错误。我应该在哪里设置要更新的视频的ID?更新视频标题或说明的请求格式是什么?

1 个答案:

答案 0 :(得分:9)

请求格式是发送“视频资源”JSON数据包,如下所示:

{
"id": "GS9h8M3ep-M",
"kind": "youtube#video",
"etag": "\"MhkxP1IuK4vYJ-nhM3d9E49-2oU/HUmayeWdVX19XyvhE5c2RnbZjgA\"",
"snippet": {
    "publishedAt": "2012-11-10T09:36:49.000Z",
    "channelId": "UC070UP0rK7rShCW1x4B4bgg",
    "title": "Finding Ourselves: The Humanities as a Discipline",
    "description": "Lecture delivered by Geoffrey Harpham, of the National Humanities Center, at the inaugural event of the Brigham Young University Humanities Center.",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/GS9h8M3ep-M/default.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/GS9h8M3ep-M/mqdefault.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/vi/GS9h8M3ep-M/hqdefault.jpg"
     }
    },
    "categoryId": "27",
    "tags": [
      "humanities",
      "Harpham",
      "BYU"
    ]
  }
}

进行更新时,您只需要发送“id”和“kind”值,在这种情况下,还需要发送部分“代码段”。但是,请注意,对于可写属性 - snippet.title,snippet.description,snippet.tags,snippet.categoryId和status.privacyStatus - 省略它们将使它们恢复为默认值(“public”为privacyStatus,空白对于其他4)。如果你要省略categoryId,那么它会导致一个错误的请求,因为它就像你将它设置为无类别一样,并且Youtube不允许视频没有类别(这是,然后,使categoryId成为事实上必需的元素)。您还必须重新包含标签,说明和隐私状态(除非您希望它默认为公共),因此不会清除它们。因此,要修改标题,您需要包含代码段,标题和类别ID,如下所示:

{
 "id": "GS9h8M3ep-M",
 "kind": "youtube#video",
 "snippet": {
    "title": "I'm being changed.",
    "categoryId": "27",
    "tags": [
      "humanities",
      "Harpham",
      "BYU"
    ],
    "description": " can be changed, too, but if I'm not to be I still have to be included as I was before. I will be emptied out if omitted."
  }
 }