调用Reports API v1时出错

时间:2013-09-03 16:38:30

标签: python google-api google-api-python-client google-admin-sdk

调用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.">

以前有人见过这个错误吗?我错过了什么? 我只是不明白为什么会出现这个或我应该检查什么。

问候。

编辑:

验证

        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)

实际通话:

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

其他API只适用于该服务帐户。 “https://www.googleapis.com/auth/admin.reports.usage.readonly”已正确添加到OAuth2域配置页。

1 个答案:

答案 0 :(得分:1)

尝试:

    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')

使用带有Admin SDK的服务帐户时,您仍需要代表Google Apps实例中的管理员行事。

此外,请确保已授予服务帐户客户端ID使用Google Apps控制台中的Reports API范围的权限。 Google云端硬盘文档describe this process well,只是在“报告”范围内。