【问题标题】:Get youtube trends v3 country wise in Json?在 Json 中获取 youtube 趋势 v3 国家明智?
【发布时间】:2015-08-09 02:48:04
【问题描述】:

如何在 Json 中按国家/地区获取 最受欢迎 或 观看次数最多 的 youtube 趋势。

以前使用 youtube 供稿 v2。似乎已弃用, https://gdata.youtube.com/feeds/api/standardfeeds/IN/most_popular?v=2

我能否获得 youtube api v3 或任何其他结果,例如趋势仪表板, https://www.youtube.com/trendsdashboard

【问题讨论】:

    标签: youtube-api youtube-data-api


    【解决方案1】:
    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);
            })
    
          }
        );
    }); 
    

    将文件另存为.js

    在HTML 文件中制作div 或ul by id="trending"

    喜欢:

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

    检查你的输出。

    • 注意 不要忘记替换您的API KEY

    【讨论】:

      【解决方案2】:

      根据 YouTube 指南,YouTube Feeds v2 现已弃用。您应该使用YouTube Data API v3。

      对于最受欢迎的视频:

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

      1. 部分:

        • 可以包含在参数值中的部件名称有:
          • id, snippet, contentDetails, fileDetails, liveStreamingDetails, localizations, player, processingDetails, recordingDetails, statistics, status, suggestions, and topicDetails
      2. 图表:

        • chart 参数标识您要检索的图表(字符串)
          • 示例mostPopular
      3. 区域代码:

        • 参数值是一个ISO 3166-1 alpha-2国家代码(字符串)
      4. 键:

      5. ma​​xResults:默认值 5,

      Read More

      【讨论】:

      • @AshishChaturvedi 感谢您的回答。但是这个 URL 只给出了四个结果。我的意思是四个视频。有没有办法获得至少 10 个视频?
      • @Sasa1234 默认提供 5 个结果,更多你应该使用 &maxResults=25
      • 请问我可以获取较早的热门视频吗?例如为日期添加一个参数,如 &date=2-2-16
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-19
      • 2015-06-27
      • 2022-07-29
      • 2015-09-08
      • 2013-08-09
      • 2014-03-02
      • 1970-01-01
      相关资源
      最近更新 更多