6

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

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

4

1 回答 1

11

请求格式是发送一个“视频资源”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”。但是请注意,对于可写属性——snippet.title、snippet.description、snippet.tags、snippet.categoryId 和 status.privacyStatus——省略它们将使它们恢复为默认值(privacyStatus 为“public”,空白对于其他 4)。如果您要省略 categoryId,那么它会导致错误的请求,因为就好像您将其设置为没有类别,并且 Youtube 不允许视频没有类别(这是,然后,使 categoryId 成为事实上的必需元素)。您还必须重新包含标签、描述和隐私状态(除非您希望它默认为公开),这样它们就不会被清除。因此,要修改标题,您'

{
 "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."
  }
 }
于 2012-11-20T21:00:21.940 回答