如何从频道中获取前10个视频,并在响应中包含观看次数 [英] How to get top 10 videos from your channel with the views count included in the response

查看:98
本文介绍了如何从频道中获取前10个视频,并在响应中包含观看次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个可以连接到youtube的ouath网络应用程序.我使用youtube Analytics(分析)电话从我的频道获取信息,例如订阅者数量.但是现在,我尝试制作频道中排名前10位的视频,并将观看次数计入响应中包含的每个视频.我使用以下文档: 已订阅或未订阅观众的热门视频

So I have a ouath web app that connects to youtube. I use the youtube analytics calls to get information like number of subscribers from my channel. But right now I try to make a top 10 videos from my channel with the views count for every video included in the response. I use this documentation: Top videos for subscribed or unsubscribed viewers

我的呼叫看起来像这样:

My call looks like this:

  $command = 'curl -H "Authorization: Bearer ' . $access_token  . '" "https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel%3D%3DMINE&start-date=' . date('Y-m-d', strtotime('-31 days')) . '&end-date=' . date('Y-m-d', strtotime('today')). '&metrics=views&dimensions=video&sort=views"';

但是我收到一条错误消息作为响应:

But I get an error message as a response:

"The query is not supported. Check the documentation at https://developers.google.com/youtube/analytics/v1/available_reports for a list of supported queries."

我还使用YoTube数据API尝试了此调用:

I also tried this call with YoTube data API:

        $videos_url = 'https://www.googleapis.com/youtube/v3/search?part=snippet&forMine=true&order=viewCount&type=video&access_token=' . $access_token;

但是它提供了以下响应:

But it provides this response:

 ["kind"]=>
    string(26) "youtube#searchListResponse"
    ["etag"]=>
    string(57) ""######""
    ["nextPageToken"]=>
    string(112) "#######"
    ["pageInfo"]=>
    object(stdClass)#267 (2) {
      ["totalResults"]=>
      int(1)
      ["resultsPerPage"]=>
      int(5)
    }
    ["items"]=>
    array(1) {
      [0]=>
      object(stdClass)#270 (4) {
        ["kind"]=>
        string(20) "youtube#searchResult"
        ["etag"]=>
        string(57) ""#####""
        ["id"]=>
        object(stdClass)#269 (2) {
          ["kind"]=>
          string(13) "youtube#video"
          ["videoId"]=>
          string(11) "####"
        }
        ["snippet"]=>
        object(stdClass)#273 (6) {
          ["publishedAt"]=>
          string(24) "2016-09-14T14:49:49.000Z"
          ["channelId"]=>
          string(24) "#####"
          ["title"]=>
          string(12) "My Slideshow"
          ["description"]=>
          string(87) "I created this video with the YouTube Slideshow Creator (http://www.youtube.com/upload)"

此响应不提供观看次数.每个视频我都需要同时获得观看次数. 关于如何做到这一点的任何想法?欢迎任何帮助!谢谢大家的宝贵时间!

This response provides no views count. I need for every video to get the views count as well. Any ideas on how to accomplish this? Any help is welcomed! Thank you all for your time!

推荐答案

您的YouTube分析api请求的问题是sort参数.尝试使用值-views而不是views.您可以仔细检查您提供的API链接.还要设置max-results

The issue with your youtube analytics api request is sort parameter. Try using value -views instead of views. You can double check the API link you provided. Also set the max-results

示例网址:

https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel%3D%3Dmine&start-date=2016-05-01&end-date=2016-09-01&metrics=views&dimensions=video&max-results=10&sort=-views&key={YOUR_API_KEY}

这篇关于如何从频道中获取前10个视频,并在响应中包含观看次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆