Get youtube trends v3 country wise in Json?

喜夏-厌秋 提交于 2019-12-17 23:30:12

问题


How to get youtube trends of most popular or most viewed by country wise in Json.

Previously using youtube feeds v2. It seems deprecated, https://gdata.youtube.com/feeds/api/standardfeeds/IN/most_popular?v=2

Can I get youtube api v3 or any other result like the trends dashboard, https://www.youtube.com/trendsdashboard


回答1:


As per YouTube guidelines, YouTube Feeds v2, is now deprecated. You should work with YouTube Data API v3.

For the most popular video:

https://www.googleapis.com/youtube/v3/videos?part=contentDetails&chart=mostPopular&regionCode=IN&maxResults=25&key=API_KEY

  1. part:

    • The part names that you can include in the parameter value are:
      • id, snippet, contentDetails, fileDetails, liveStreamingDetails, localizations, player, processingDetails, recordingDetails, statistics, status, suggestions, and topicDetails
  2. chart:

    • The chart parameter identifies the chart that you want to retrieve (string)
      • Example mostPopular
  3. regionCode:

    • The parameter value is an ISO 3166-1 alpha-2 country code (string)
  4. key:

    • Google Project API key
  5. maxResults : Default value 5 ,

Read More




回答2:


var maxVideos = 5;
   $(document).ready(function(){
  $.get(
    "https://www.googleapis.com/youtube/v3/videos",{
      part: 'snippet',
      chart: 'mostPopular',
      kind: 'youtube#videoListResponse',
      maxResults: maxVideos,
      regionCode: 'IN',
      key: 'Your_KEY_Here'},
      function(data){
        var output;
        $.each(data.items, function(i, item){
          console.log(item);
          videTitle = item.snippet.title;
                description = item.snippet.description;
                thumb = item.snippet.thumbnails.high.url;
                channelTitle = item.snippet.channelTitle;
                videoDate = item.snippet.publishedAt;
                Catagoryid = item.snippet.categoryId;
                cID = item.snippet.channelId;
          output = '<div class="maindiv"><div>' +
                        '<a data-fancybox-type="iframe" class="fancyboxIframe" href="watch.php?v=' + vidId + '" target="_blank" ><img src="' + thumb + '" class="img-responsive thumbnail" ></a>' +
                        '</div>' +
                        '<div class="input-group col-md-6">' +
                            '<h3 class="Vtitle"><a data-fancybox-type="iframe" class="fancyboxIframe" href="watch.php?v=' + vidId + '" target="_blank">' + videTitle + '</a></h3>'+
                        '</div><div  id="cTitle"><a href="https://www.youtube.com/channel/'+cID+'" target="_blank">'+channelTitle+'</a></div></div>' +
                    '<div class="clearfix"></div>';
          $('#trending').append(output);
        })

      }
    );
}); 

Save file as .js

And in HTML file make div or ul by id="trending"

like:

<div id="catagoryname"><h1>Trending</h1></div>
      <ul id="trending"></ul>

The check your out put.

  • Note Don't forget to Replace your API KEY


来源:https://stackoverflow.com/questions/30475309/get-youtube-trends-v3-country-wise-in-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!