Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Youtube Analytics API: 403 forbidden error despite valid token

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.

like image 701
ashrewdmint Avatar asked May 17 '13 00:05

ashrewdmint


People also ask

How do I fix error 403 Forbidden on Google?

A 403 Forbidden Error occurs when you do not have permission to access a web page or something else on a web server. It's usually a problem with the website itself. However, you can try refreshing the page, clearing your cache and cookies, and disconnecting from any VPN you might be using.

What does YouTube error 403 mean?

Description. forbidden (403) forbidden. Access forbidden. The request may not be properly authorized.


2 Answers

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.

like image 88
breno Avatar answered Oct 22 '22 08:10

breno


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

like image 1
Josh M Avatar answered Oct 22 '22 07:10

Josh M