12

So, I have a valid OAuth token for a channel. When the token expires, it is automatically refreshed. This token works for requests to gdata.youtube.com, but for some reason is denied to www.googleapis.com/youtube/analytics/v1/reports.

The scope used to get the token is https://gdata.youtube.com https://www.googleapis.com/auth/yt-analytics.readonly https://www.googleapis.com/auth/youtubepartner

This works for other channels but not the one in particular.

GET www.googleapis.com/youtube/analytics/v1/reports
  PARAMS
    ?metrics=views
    &ids=channel==...
    &start-date=...
    &end-date=...
  HEADER
    Authorization: Bearer ...
  RESPONSE
    {
      "error": {
        "errors": [
          {
            "domain": "global",
            "reason": "forbidden",
            "message": "Forbidden"
          }
        ],
        "code": 403,
        "message": "Forbidden"
      }
    }

Edit: it should be noted that when you call www.googleapis.com/youtube/analytics/v1/reports with insufficient scope, you get this error:

{domain:global, reason:insufficientPermissions, message:Insufficient Permission}

This is a completely different error from the 403 forbidden one.

ashrewdmint
  • 588
  • 4
  • 14
  • It's probably something related to the specific combination of channels and Google Account that you're authenticating against. I'll follow up directly to get some information that's not appropriate for posting in public. – Jeff Posnick May 21 '13 at 20:38
  • 1
    @ashrewdmint have you resolved this problem? I have the same issues for random youtube channels. It works couple days and suddenly stops and throws 403. This only happens for youtube analytics, other youtube api endpoints works o_O. Thank you. – User May 29 '18 at 08:35

3 Answers3

1

You probably need to enable YouTube Analytics for your project. Go the the APIs console: https://code.google.com/apis/console, select your project, then click on the services tab, search for YouTube Analytics, and enable it, after reading and accepting the ToS. Remember to validate that the free quota is sufficient for your uses or request additional quota.

breno
  • 3,226
  • 1
  • 22
  • 13
1

We came across the same permissions error. Unless the user is apart of the Youtube Partner Program, you'll be unable to retrieve the content owner reports:

https://developers.google.com/youtube/analytics/v1/content_owner_reports

"Note: Content owner reports are only accessible to YouTube content partners who participate in the YouTube Partner Program."

But you can still retrieve the Channel Reports for regular users:

https://developers.google.com/youtube/analytics/v1/channel_reports

Josh M
  • 11
  • 1
  • I'm not sure this is applicable because we're setting id=channel==CHANNEL_ID, not id=contentOwner==OWNER_NAME, indicating that we are not returning content owner reports. Thanks for your response, though. – ashrewdmint Jun 25 '13 at 20:45
0

After enabling YouTube Analytics for my project, I still got the Forbidden Error. In my case, I got it apparently because I was trying to access my brand account analytics, and not my personal channel analytics.

This answer solved the problem for me.

and I needed to add myself as Test User under the Google Cloud Project --> OAuth consent screen

Johanna
  • 566
  • 1
  • 4
  • 17