Search code examples
google-apigoogle-oauthgoogle-oauth-java-client

Google OAuth Access tokens for different APIs


I'm trying to access Reports API. And created source code for this on Java (GitHub project).

I can get Access Token, but if I use it for Reports API Google always return me "Access denied. You are not authorized to read activity records" error.

I tried this Access Token to receive information from Drive API and it works. So Access Token is valid for Drive API and not valid for Reports API.

On this page I found this information - Using OAuth 2.0 to Access Google APIs

Access tokens are valid only for the set of operations and resources described in the scope of the token request. For example, if an access token is issued for the Google+ API, it does not grant access to the Google Contacts API. You can, however, send that access token to the Google+ API multiple times for similar operations.

So I can't use one Access token for all APIs? If so how can I get Access Token for Reports API?

I'm using Service Account JSON for access token generation.

Thank you for help! Aleks.


Solution

  • So I can't use one Access token for all APIs?

    When you authncate a user you request some scopes this tells the user what apis and data you need access to. There are a lot of Scopes each scopes gives you acccess to diffrent data.

    If so how can I get Access Token for Reports API?

    You include the scope for that api in your authentication code. Its hard to know which reports api you are talking about

    There is also the Google analytics reporting api, and the Youtube analytics reports. The easiest way to know what scope you need to include is to check the doucmentation page for the method you are using they will always include an auth section telling you which scope you need in order to use it.