11

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

我可以通过对搜索端点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/videos?id=IytNBm8WA1c&part=snippet&key= {YOUR_API_KEY}

回复,

{
 "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 - https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.videos.list?id=IytNBm8WA1c&part=snippet&_h=3&

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

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

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

4

4 回答 4

23

根据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}
于 2015-10-31T03:51:38.917 回答
1

不幸的是,目前您只能在验证自己为频道所有者的情况下获取带有标签的视频。搜索过去可以工作的标签,但在当前的 V2 实现中被破坏了。

于 2013-04-29T10:43:38.497 回答
1

以下方法获取 YouTube 标题、描述和标签

  1. 首先创建 Google API 密钥
    https://console.cloud.google.com/home/dashboard

  2. 转到凭据 - 创建 API 密钥
    https://console.cloud.google.com/apis/credentials?folder=&organizationId=&project=

  3. 启用 YouTube API
    https://console.developers.google.com/apis/api/youtube.googleapis.com/overview?project=

  4. 下载邮递员软件以在谷歌服务器 YouTube API 上发布数据
    https://www.googleapis.com/youtube/v3/videos?key=your-key&fields=items(snippet(title,description,tags))&part=snippet&id=youtube- ID

于 2020-12-09T06:32:08.623 回答
0

我在我的 javascript 中检索了这样的视频标签,你可以看到 -这里

function getYouTubeTags() {

var q = document.getElementById("query").value;

VID_REGEX = /(?:youtube(?:-nocookie)?\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/;

var vidid = q.match(VID_REGEX)[1];
var key = "...";

var newrequest = new XMLHttpRequest();
newrequest.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {

        var data = JSON.parse(this.responseText).items[0].snippet;
        //   document.getElementById("keyword").innerHTML = data.tags;
        document.getElementById("titlen").innerHTML = data.title;

        var i;
        var cell4 = document.getElementById('tgs');
        for (i = 0; i < data.tags.length; i++) {

            var element3 = document.createElement("input");
            element3.type = "button";
            element3.name = "add";
            element3.value = data.tags[i];
            element3.className = "btn btn-danger";
            cell4.appendChild(element3);

            /*to set Image*/
            document.getElementById("myImg").src = "https://img.youtube.com/vi/" + vidid + "/hqdefault.jpg";

        }

    }
};

newrequest.open('GET', "https://www.googleapis.com/youtube/v3/videos?id=" + vidid + "&key=" + key + "&fields=items(snippet(title,description,tags))&part=snippet", true);

newrequest.send(); }
于 2020-09-19T18:22:14.210 回答