1

I am using OAuth2 server-to-server.

I am getting this message:

HTTP Status: 403

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

I enabled all the Youtube APIs.

Here is my code:

    $service_token_arr = json_decode($_SESSION['service_token'], true);
    $access_token = $service_token_arr['access_token'];

    $url = 'https://www.googleapis.com/youtube/analytics/v1/reports';
    $params = '?end-date=2015-09-10&ids=channel%3D%3D' . YOUTUBE_CHANNEL_ID . '&metrics=views&start-date=2015-05-01&dimensions=day&sort=day';

    $ch = curl_init( $url . $params );

    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $access_token));
    //curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
    //curl_setopt($ch, CURLOPT_TIMEOUT, 40);

    //execute post
    $result = curl_exec( $ch );
    $http_code = curl_getinfo( $ch, CURLINFO_HTTP_CODE );

    if($http_code != '200') {
        //error_log( get_bloginfo('name') . ' - Facebook Page - HTTP ' . $http_code . ' Error.' );
        echo '[Error:' . $http_code . ']';
    }

Here is the scope I am using:

$scopes = 'https://www.googleapis.com/auth/yt-analytics.readonly';

I am using PHP CURL because the Google PHP SDK does not support Youtube Analytics.

I forgot to also indicate that under one account I have multiple Youtube Accounts. I am unsure how to make it work with the API. But I suspect this as something to do with my issue.

Is there something that I am missing?

I am only trying to get my videos views per day.

jnbdz
  • 4,863
  • 9
  • 51
  • 93

0 Answers0