【问题标题】:Error calling Reports API v1调用 Reports API v1 时出错
【发布时间】:2013-09-06 23:43:20
【问题描述】:

我在调用 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 域配置页面。

【问题讨论】:

  • 您以谁身份进行身份验证? Google Apps 实例中的经销商或超级管理员?它有助于查看您的实际代码,而不仅仅是您遇到的错误。
  • 嗨,杰。我正在编辑问题以显示一些代码...

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


【解决方案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 控制面板中的报告 API 范围的权限。 Google Drive 文档describe this process well,只是在报告范围内的子目录。

【讨论】:

  • 还是没有运气。这次我得到一个 AccessTokenRefreshError(无法连接:access_denied)。对于其他 Admin SDK 调用,我使用 prn='super-admin@yourdomain.com',但它在此 Reports 调用中给出了相同的错误。
  • 查看更新的答案。您需要确保服务帐户已被授予对 CPanel 中给定范围的访问权限。
  • 已解决。我以为我已经添加了使用范围和审计范围(admin.reports.audit.readonly),但我错了。谢谢!
  • 似乎假设 Oauth 1.0。 @JayLee 的 Google Dive example cited above 将您引导至“选择管理第三方 OAuth 客户端访问”,这导致有关 1.0 的文档被弃用。对 2.0 的建议?
  • 好的。在职的。在将域范围的权限委派给服务帐户下的Using OAuth 2.0 for Server to Server Applications 中,应更改s/Manage third party OAuth Client access/Manage API client access/。 @JayLee
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-04-16
  • 1970-01-01
  • 2022-07-20
  • 1970-01-01
  • 2021-07-07
  • 1970-01-01
  • 2017-03-06
相关资源
最近更新 更多