【问题标题】:Google Reports API - reports.customerUsageReports.get issueGoogle Reports API -reports.customerUsageReports.get 问题
【发布时间】:2016-08-30 16:56:07
【问题描述】:

我在使用 Google Reports API 时遇到了一些问题。我运行documentation 中提供的示例代码以获取reports.activities.list 数据没有问题,但是当我更改程序以尝试提取完整的域数据(reports.customerUsageReports.get)时,我收到一条错误消息那个“'Resource'对象没有属性'usage'”。

我对 auth 没有任何问题,已根据需要将程序中的 api 范围更改为 https://www.googleapis.com/auth/admin.reports.usage.readonly

我正在运行以下 sn-p 来尝试访问数据

credentials = get_credentials()
    http = credentials.authorize(httplib2.Http())
    service = discovery.build('admin', 'reports_v1', http=http)

    print('Getting data')
    results = service.usage().list(date='2016-01-01').execute()
    usage = results.get('items', [])

    if not usage:
        print('No data found.')
    else:
        print('Data:')
        for use in usageReports:
            print(use)

【问题讨论】:

    标签: python google-api google-apps google-reporting-api


    【解决方案1】:

    确保您遵循以下步骤:

    1. 根据Python quickstart,如果修改范围,需要删除之前保存在~/.credentials/admin-reports_v1-python-quickstart.json的凭证

    2. 对于范围,在使用 OAuth 2.0 请求访问时,您的应用程序需要范围信息,以及 Google 在您注册应用程序时提供的信息(例如客户端 ID 和客户端密码)。

    有关更多信息,请查看此link 和有关CustomerUsageReports: get 的文档以了解如何正确使用这些参数。

    【讨论】:

      【解决方案2】:

      你要调用的方法是:

      service.customerUsageReports()
      

      你在打电话:

      service.usage()
      

      这不存在。

      【讨论】:

        猜你喜欢
        • 2020-09-05
        • 2021-08-11
        • 2017-05-31
        • 2019-10-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-05-03
        相关资源
        最近更新 更多