YouTube Analytics API php Samples

后端 未结 3 1350
别跟我提以往
别跟我提以往 2021-01-06 13:04

I want to make this YouTube Analytics Request with the PHP Client Libary

https://www.googleapis.com/youtube/analytics/v1/reports  
?ids=channel==CHANNELID
         


        
3条回答
  •  别那么骄傲
    2021-01-06 13:41

    You can add metrics in the following way rather than calling each metric one by one.

    $metrics = 'views,estimatedMinutesWatched,averageViewDuration,comments,favoritesAdded,favoritesRemoved,likes,dislikes,shares,subscribersGained,subscribersLost';
    

    Your result will be in the from as depicted in the documentation. Example:

    $optparams = array(
        'dimensions' => '7DayTotals',
        'sort' => 'day',
    );
    
    $metrics = 'views,estimatedMinutesWatched,averageViewDuration,comments,favoritesAdded,favoritesRemoved,likes,dislikes,shares,subscribersGained,subscribersLost';
    
    $api_response = $metrics;
    $api = $analytics->reports->query($id, $start_date, $end_date, $metric, $optparams);
    
    if (isset($api['rows'])) {
        //Get values in form of multidimensional arrays. 
    }
    

提交回复
热议问题