首页 > 解决方案 > Youtube 分析 API v2 迁移

问题描述

由于 YouTube Analytics API (v1) 自 2018 年 11 月 1 日起已弃用(来源),我一直在尝试将其迁移到 v2。

我下载了以下链接的升级表格: https ://github.com/googleapis/google-api-php-client-services

迁移文档如下: 在此处输入链接描述

以下是代码:

$youtubeAnalytics       =   new Google_Service_YouTubeAnalytics($client);
$channel                =   "channel==" . $channelId;
$metrics                =   'views,redViews,comments,likes,dislikes,videosAddedToPlaylists,videosRemovedFromPlaylists,shares,estimatedMinutesWatched,estimatedRedMinutesWatched,averageViewDuration,averageViewPercentage,annotationClickThroughRate,annotationCloseRate,annotationImpressions,annotationClickableImpressions,annotationClosableImpressions,annotationClicks,annotationCloses,cardClickRate,cardTeaserClickRate,cardImpressions,cardTeaserImpressions,cardClicks,cardTeaserClicks,subscribersGained,subscribersLost';
$optParams              =   array('dimensions' => 'day'
// to fetch daily analytics
);
$startDate              =   date('Y-m-d');
// for first crawl
$endDate                =   date("Y-m-d", strtotime('-90 days'));
if ($user['last_used'] != '') {
    $endDate            =   date("Y-m-d", strtotime('-10 days')); // if not the first crawl

}

// fetching the daily channel analytics : Youtbe Analytics API
$api                    =   $youtubeAnalytics->reports->query($channel, $endDate, $startDate, $metrics, $optParams);

$api 返回空白。

我修改了 request.query 函数以在整个系统中应用更改。如下: 路径:google/apiclient-services/src/Google/Service/YoutubeAnalytics/Resources/Reports.php

public function query($ids, $startDate, $endDate, $metrics, $optParams = array())
  {
    $params = array('ids' => $ids, 'startDate' => $startDate, 'endDate' => $endDate, 'metrics' => $metrics);
    $params = array_merge($params, $optParams);
    return $this->call('query', array($params), "Google_Service_YouTubeAnalytics_QueryResponse");
  }

我在这里没有得到回复:路径:google > apiclient/src/Google/Service/Resource.php

$request = new Request(
        $method['httpMethod'],
        $url,
        ['content-type' => 'application/json'],
        $postBody ? json_encode($postBody) : ''
    );

如果问题感觉不正确,我深表歉意。这是我第一次使用 Youtube API。请帮忙。

标签: migrationyoutube-data-apiyoutube-analytics-api

解决方案


推荐阅读