Question

I'm getting an error while calling the Reports API:

<HttpError 403 when requesting https://www.googleapis.com/admin/reports/v1/usage/users/all/dates/2013-08-01?alt=json&maxResults=1 returned "Caller does not have access to the customers reporting data.">

Have anyone seen this error before? What am I missing? I just can't see why this is showing or what I should be checking.

Regards.

EDIT:

Auth:

        credentials = SignedJwtAssertionCredentials(
            service_account_name='5163XXXXX@developer.gserviceaccount.com',
            private_key=oauth2_private_key,
            scope='https://www.googleapis.com/auth/admin.reports.usage.readonly')

        # https://developers.google.com/api-client-library/python/guide/thread_safety
        http = credentials.authorize(httplib2.Http())

        service = apiclient.discovery.build('admin', 'reports_v1', http=http)

The actual call:

result = service.userUsageReport().get(
    userKey='all',
    date='2013-08-01',
    maxResults=1).execute()

Other APIs just work fine with that service account. 'https://www.googleapis.com/auth/admin.reports.usage.readonly' has been properly added to OAuth2 domain config page.

Was it helpful?

Solution

Try:

    credentials = SignedJwtAssertionCredentials(
        service_account_name='5163XXXXX@developer.gserviceaccount.com',
        private_key=oauth2_private_key,
        scope='https://www.googleapis.com/auth/admin.reports.usage.readonly',
        sub='super-admin@yourdomain.com')

when using Service Accounts with Admin SDK, you still need to act on behalf of an admin within the Google Apps instance.

Also, make sure that the Service Account Client ID has been granted rights to use the Reports API scopes in the Google Apps Control Panel. The Google Drive docs describe this process well, just sub in the Reports scopes instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top