Search code examples
youtubeyoutube-apiyoutube-analytics-apiyoutube-analytics

youtube analytics api subscribers views issue


I have a problem with receiving subscriber views. After passing the authorization and receiving the access token, I want to get the number of views of my youtube channel. But I get the following answer from Api:

{
"error": {
"errors": [
  {
   "domain": "global",
   "reason": "forbidden",
   "message": "Forbidden"
  }
],
"code": 403,
"message": "Forbidden"

During authorization I use the following scopes:

  1. https://www.googleapis.com/auth/yt-analytics.readonly
  2. https://www.googleapis.com/auth/youtube

My request to Youtube Analytics:

$root = 'https://www.googleapis.com/youtube/analytics/v1/reports?';
    $params = [
        'ids' => 'channel=='.$my_channel_id,
        'dimensions' => 'day,subscribedStatus',
        'start-date' => $start_date,
        'end-date' => $end_date,
        'filters' => 'subscribedStatus==SUBSCRIBED',
        'metrics' => 'views',
        'access_token' => $my_access_token,
    ];
    $prms = $params;
    $params = http_build_query($params);
    $request = $root.$params;
    $res = $this->requestAPI($request);

Solution

  • So, youtube api has some limitation on issuing information related to subscribers. The actant from which information is taken must have a certain number of subscribers. The exact amount I do not know, but maybe it equals 500