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

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

问题描述

所以我有一个连接到 youtube 的 ouath 网络应用程序.我使用 youtube 分析调用从我的频道获取诸如订阅者数量之类的信息.但是现在我尝试从我的频道制作前 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

我的电话是这样的:

  $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;

但它提供了这个响应:

 ["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天全站免登陆