javascript 如何使用 YouTube v3 API 检索 YouTube 视频的标签?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16240499/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 03:51:57  来源:igfitidea点击:

How to retrieve a YouTube video's tags with YouTube v3 API?

javascriptgoogle-apiyoutube-api

提问by KRB

I want to retrieve the tags for a specific YouTube video using v3 of the YouTube API.

我想使用 YouTube API 的 v3 检索特定 YouTube 视频的标签。

I'm able to retrieve a video with this request to the search endpoint, https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=1&q=cats&type=video&key={YOUR_API_KEY}.

我可以通过此请求检索视频到搜索端点https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=1&q=cats&type=video&key={YOUR_API_KEY}。

Now I hit the video endpoint trying to get the tags for the video from the above query. https://www.googleapis.com/youtube/v3/videos?id=IytNBm8WA1c&part=snippet&key={YOUR_API_KEY}

现在我点击了视频端点,试图从上述查询中获取视频的标签。 https://www.googleapis.com/youtube/v3/videos?id=IytNBm8WA1c&part=snippet&key={YOUR_API_KEY}

Response,

回复,

{
 "kind": "youtube#videoListResponse",
 "etag": "\"PMn2rAVTRiZHkX45qiqfcLZoTXM/rYBuk4KeZFmSMoiSuaXfy6-Pm28\"",
 "items": [
  {

   "id": "IytNBm8WA1c",
   "kind": "youtube#video",
   "etag": "\"PMn2rAVTRiZHkX45qiqfcLZoTXM/_6K6Qz8rLYf0d5gUnucV1LwbwU4\"",
   "snippet": {
    "publishedAt": "2007-07-09T14:02:03.000Z",
    "channelId": "UCFMV3DqmnaRc4oNGvi-3OvQ",
    "title": "Funny Cats",
    "description": "it's soo funny :D\r\n\r\naudio content is licensed by UMG\r\n\r\nSong 1: Gioachino Rossini - The Thieving Magpie  0:00 - 1:37\r\nSong 2: The Presidents of the United States of America - Kitty  1:38 - 2:47\r\nSong 3: The Nutcracker  2:48 - 3:51\r\nSong 4: Smash Mouth - All Star  3:51 - 7:06\r\nSong 5: The Wiseguys - Ooh La La  7:07 - 7:43\r\n\r\nPS: i will ignore messages with the subject\r\n\"Business Proposal Regarding Your YouTube Videos\"",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/IytNBm8WA1c/default.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/IytNBm8WA1c/mqdefault.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/vi/IytNBm8WA1c/hqdefault.jpg"
     }
    },
    "channelTitle": "nguoap",
    "categoryId": "15"
   }
  }
 ]
}

API Explorer for this request - https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.videos.list?id=IytNBm8WA1c&part=snippet&_h=3&

此请求的 API Explorer - https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.videos.list?id=IytNBm8WA1c&part=snippet&_h=3&

Even if I authorize this request I get the same results. Although, if the account being authorized owns the video it returns the tags.

即使我授权了这个请求,我也会得到相同的结果。虽然,如果被授权的帐户拥有视频,它会返回标签

How can I get the tags for the videos I own without asking the end-user to authorize their accounts? This implementation is client side with JS.

如何在不要求最终用户授权其帐户的情况下获取我拥有的视频的标签?这个实现是客户端的 JS。

UPDATE: GData Issue Link: https://code.google.com/p/gdata-issues/issues/detail?id=4513

更新:GData 问题链接:https: //code.google.com/p/gdata-issues/issues/detail?id =4513

回答by Stephen Lead

According to https://developers.google.com/youtube/v3/docs/videos/listit appears that the latest version of the YouTube API now returns tags:

根据https://developers.google.com/youtube/v3/docs/videos/list看来,最新版本的 YouTube API 现在返回标签:

https://www.googleapis.com/youtube/v3/videos?key={API-key}&fields=items(snippet(title,description,tags))&part=snippet&id={video_id}

回答by R Keppel

Unfortunately, at present you can only get videos with tags when you authenticate yourself as the owner of the channel. Searching for tags used to work, but is brokenin the current V2 implementation.

不幸的是,目前只有当您验证自己是频道所有者时,您才能获得带有标签的视频。搜索标签曾经可以工作,但在当前的 V2 实现中被破坏了。