As the YouTube Analytics API (v1) has been deprecated as of November 1, 2018 (source), I have been trying to migrate it to v2.
I downloaded the upgrade form the following link : https://github.com/googleapis/google-api-php-client-services
and the migration documentation is as follows: enter link description here
Following is the code:
$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 return blank.
I've modified the request.query function to apply the change throughout the system. As follows: Path : 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");
}
I dont get a response over here: Path : google > apiclient/src/Google/Service/Resource.php
$request = new Request(
$method['httpMethod'],
$url,
['content-type' => 'application/json'],
$postBody ? json_encode($postBody) : ''
);
I apologies if the question feels incorrect. This is my first time working with Youtube API's. Please help.