For*_*ded 6 python google-analytics google-analytics-api google-analytics-firebase
在API的第3版中,我看到有一个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()
Run Code Online (Sandbox Code Playgroud)
Mat*_*att 12
您要查找的参数的正确名称是:pageSize.该参考文档提供完整的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()
Run Code Online (Sandbox Code Playgroud)
注意:无论您要求多少,API都会为每个请求返回最多100,000行.在您尝试max_results这样做时,这告诉我您正在尝试从Core Reporting API V3 迁移,请查看迁移指南 - 分页文档以了解如何请求下一个10,000行.
Stack Overflow额外提示.在您的问题中包含您的错误回复,因为它可能会提高您的帮助机会.