1

I'm unable to get CPM data from my Youtube reports:

I'm getting:

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

I don't even know where to begin to debug this, and I haven't found anything online.

I'm just trying to curl the endpoint, mirroring this: HERE

Notice that once you finish the oauth process, User will see "You do not have permission to execute this method." and the 403

Also, Notice if you remove 'CPM' from the list of metrics, this will work.


Example:

curl --header "Authorization: Bearer _____access_token____" -e "https://developers.google.com" https://content-youtubeanalytics.googleapis.com/v2/reports\?endDate\=2014-06-30\&ids\=channel%3D%3DMINE\&metrics\=cpm\&startDate\=2014-05-01\&key\=_____api_key____

I'm getting the refresh token via:

<script>
var auth2;
var SCOPE = ['https://www.googleapis.com/auth/adwords',
  'https://www.googleapis.com/auth/yt-analytics.readonly', 
  'https://www.googleapis.com/auth/youtube', 
  'https://www.googleapis.com/auth/yt-analytics-monetary.readonly',
  'https://www.googleapis.com/auth/youtubepartner-channel-audit',
  'https://www.googleapis.com/auth/youtubepartner',
  'https://www.googleapis.com/auth/youtube.readonly',
  ] ;

function initClient() {
  auth2 = gapi.auth2.init({
    'clientId': 'my-client-id',
    'scope': SCOPE.join(' '),
    'prompt': 'consent',
  })
}

function handleClientLoad() {
  gapi.load('auth2', initClient);
}
</script>
<script async defer src="https://apis.google.com/js/api.js"
  onload="this.onload=function(){};handleClientLoad()"
  onreadystatechange="if (this.readyState === 'complete') this.onload()">
</script>

the access token I'm using is from the refresh token via:

https://www.googleapis.com/oauth2/v4/token?client_id={my_client_id}&client_secret={my_client_secret}&refresh_token={my_refresh_token}&grant_type=refresh_token

and I'm getting:

{
 "access_token": "ya29.GlvyBZVPpC.....",
 "token_type": "Bearer",
 "expires_in": 3600,
 "scope": "https://www.googleapis.com/auth/youtubepartner https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/adwords https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/youtube.readonly https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/yt-analytics.readonly https://www.googleapis.com/auth/yt-analytics-monetary.readonly",
 "id_token": "eyJhbGciOiJSUz...."
}

I don't believe it's an issue with my scopes as I am not getting a 403 like:

{
  "error": {
    "code": 403,
    "message": "Request had insufficient authentication scopes.",
    "errors": [
      {
        "message": "Request had insufficient authentication scopes.",
        "domain": "global",
        "reason": "forbidden"
      }
    ],
    "status": "PERMISSION_DENIED"
  }
}
user3662456
  • 267
  • 2
  • 11
  • please edit your question and include your code we cant debug what we cant see – Linda Lawton - DaImTo Aug 07 '18 at 22:28
  • @DaImTo did you need more information for this ticket? – user3662456 Aug 09 '18 at 19:09
  • please include your authentication code as well sounds like you are using the wrong scope – Linda Lawton - DaImTo Aug 10 '18 at 02:40
  • @DaImTo I appreciate the help. I'm really blocked on this one. I don't believe it's an issue with the scopes, but if there's any more info I can provide, let me know. – user3662456 Aug 10 '18 at 17:44
  • again please include you authentication code how are you getting the refresh token. the error means you don't have permission to do what you are trying to do. either the user dosent have access or you are using the wrong scope – Linda Lawton - DaImTo Aug 11 '18 at 02:00
  • @DaImTo I want to refocus the issue on https://developers.google.com/apis-explorer/#p/youtubeAnalytics/v2/youtubeAnalytics.reports.query?endDate=2014-06-30&ids=channel%253D%253DMINE&metrics=views%252Ccomments%252Clikes%252Cdislikes%252CestimatedMinutesWatched%252CaverageViewDuration%252Ccpm&startDate=2014-05-01&_h=2&. I believe you're saying the scopes on the developer page was insufficient to get cost data (such as cpm) and if so, what recourse do i have for that data. I'm testing with a new gmail account without videos so I'm expecting to get 0s in my 200 rather than a 403. – user3662456 Aug 12 '18 at 18:44
  • don't use apis explore to get the refresh token use your own code please and let me know if you are still having a problem – Linda Lawton - DaImTo Aug 12 '18 at 21:29
  • I'm using https://developers.google.com/identity/sign-in/web/reference to get the refresh tokens. I'm not getting it from the apis explore – user3662456 Aug 13 '18 at 03:38

0 Answers0