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

前端 未结 4 564
暖寄归人
暖寄归人 2020-12-20 15:17

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

I\'m able to retrieve a video with this request to the search endpoint, https:/

相关标签:
4条回答
  • 2020-12-20 15:35

    I retrived video tags like this in my javascript , you can see - here

    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(); }
    
    0 讨论(0)
  • 2020-12-20 15:42

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

    https://www.googleapis.com/youtube/v3/videos?key={API-key}&fields=items(snippet(title,description,tags))&part=snippet&id={video_id}
    
    0 讨论(0)
  • 2020-12-20 15:42

    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 broken in the current V2 implementation.

    0 讨论(0)
  • 2020-12-20 15:44

    Following method to fetch YouTube title, description and tags

    1. First of all create Google API key
      https://console.cloud.google.com/home/dashboard

    2. go to credentials - create API key
      https://console.cloud.google.com/apis/credentials?folder=&organizationId=&project=

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

    4. download postman software to POST data on google server YouTube API
      https://www.googleapis.com/youtube/v3/videos?key=your-key&fields=items(snippet(title,description,tags))&part=snippet&id=youtube-id

    0 讨论(0)
提交回复
热议问题