简体   繁体   English

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

[英]Setting Max Results in API v4 (python)

In v3 of the API I'm seeing that there was a max-results parameter that could be passed to get more than 1000 records. 在API的第3版中,我看到有一个max-results参数可以传递以获得超过1000条记录。 I haven't been able to figure out how to pass that parameter in v4 of the API using python. 我无法弄清楚如何使用python在API的v4中传递该参数。

My code looks something like below. 我的代码如下所示。 I've commented out my best guess at max_result. 我已经在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()

The correct name of the parameter you are looking for is: pageSize . 您要查找的参数的正确名称是: pageSize The Reference Docs provide the full API specifications. 参考文档提供完整的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()

Note: the API returns a maximum of 100,000 rows per request, no matter how many you ask for. 注意:无论您要求多少,API都会为每个请求返回最多100,000行。 As you attempted max_results this tells me you are trying to migrate from the Core Reporting API V3, check out the Migration Guide - Pagination documentation to understand how to request the next 10,000 rows. 当您尝试max_results这告诉我您正在尝试从Core Reporting API V3 迁移 ,请查看迁移指南 - 分页文档以了解如何请求下一个10,000行。

Stack Overflow extra tip. Stack Overflow额外提示。 Include your error responses in your question, as it will likely improve your chances of someone being able to help. 在您的问题中包含您的错误回复,因为它可能会提高您的帮助机会。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM