在 API v4 (python) 中设置最大结果

Setting Max Results in API v4 (python)

在 API 的 v3 中,我看到有一个 max-results 参数可以传递以获取超过 1000 条记录。我一直无法弄清楚如何使用 python 在 API 的 v4 中传递该参数。

我的代码如下所示。我在 max_result.

评论了我最好的猜测
def get_report(analytics):
  # Use the Analytics Service Object to query the Analytics Reporting API V4.
  return analytics.reports().batchGet(
      body={
        'reportRequests': [
        {
          'viewId': VIEW_ID,
          #'max_results': 100000,
          'dateRanges': [{'startDate': '2016-04-01', 'endDate': '2016-08-09'}],
          'dimensions': [{'name':'ga:date'},
                    {'name': 'ga:channelGrouping'}],
          'metrics': [{'expression': 'ga:sessions'},
                 {'expression': 'ga:newUsers'},
                 {'expression': 'ga:goal15Completions'},
                 {'expression': 'ga:goal9Completions'},
                 {'expression': 'ga:goal10Completions'}]
        }]
      }
  ).execute()

您要查找的参数的正确名称是:pageSize. The Reference Docs 提供完整的 API 规范。

def get_report(analytics):
  # Use the Analytics Service Object to query the Analytics Reporting API V4.
  return analytics.reports().batchGet(
      body={
        'reportRequests': [
        {
          'viewId': VIEW_ID,
          'pageSize': 10000,
          'dateRanges': [{'startDate': '2016-04-01', 'endDate': '2016-08-09'}],
          'dimensions': [{'name':'ga:date'},
                    {'name': 'ga:channelGrouping'}],
          'metrics': [{'expression': 'ga:sessions'},
                 {'expression': 'ga:newUsers'},
                 {'expression': 'ga:goal15Completions'},
                 {'expression': 'ga:goal9Completions'},
                 {'expression': 'ga:goal10Completions'}]
        }]
      }
  ).execute()

注意:API returns 每个请求最多 100,000 行,无论您请求多少行。当您尝试 max_results 时,这告诉我您正在尝试从 Core Reporting API V3 迁移,请查看 Migration Guide - Pagination documentation 以了解如何请求接下来的 10,000 行。

Stack Overflow 额外提示。在您的问题中包含您的错误回复,因为这可能会增加您获得帮助的机会。