Вам нужно сделать что-то вроде этого
### Something like this works for me
list = [] #I usually store the output of the pagination in a list
# pagination function
def main(client, pageTokenVariable):
return analytics.reports().batchGet(
body={
'reportRequests': [
{
'viewId': '123',
"pageToken": pageTokenVariable,
#All your other stuff like dates etc goes here
}]
}
).execute()
response = main(client, "0")
for report in response.get(reports, []) #All the stuff you want to do
pagetoken = report.get('nextPageToken', None) #Get your page token fron the FIRST request and store it a variabe
columnHeader = report.get('columnHeader', {})
dimensionHeaders = columnHeader.get('dimensions', [])
metricHeaders = columnHeader.get('metricHeader', {}).get('metricHeaderEntries', [])
rows = report.get('data', {}).get('rows', [])
for row in rows:
# create dict for each row
dict = {}
dimensions = row.get('dimensions', [])
dateRangeValues = row.get('metrics', [])
# fill dict with dimension header (key) and dimension value (value)
for header, dimension in zip(dimensionHeaders, dimensions):
dict[header] = dimension
# fill dict with metric header (key) and metric value (value)
for i, values in enumerate(dateRangeValues):
for metric, value in zip(metricHeaders, values.get('values')):
#set int as int, float a float
if ',' in value or ',' in value:
dict[metric.get('name')] = float(value)
else:
dict[metric.get('name')] = int(value)
list.append(dict) #Append that data to a list as a dictionary
while pagetoken: #This says while there is info in the nextPageToken get the data, process it and add to the list
response = main(client, pagetoken)
for row in rows:
# create dict for each row
dict = {}
dimensions = row.get('dimensions', [])
dateRangeValues = row.get('metrics', [])
# fill dict with dimension header (key) and dimension value (value)
for header, dimension in zip(dimensionHeaders, dimensions):
dict[header] = dimension
# fill dict with metric header (key) and metric value (value)
for i, values in enumerate(dateRangeValues):
for metric, value in zip(metricHeaders, values.get('values')):
#set int as int, float a float
if ',' in value or ',' in value:
dict[metric.get('name')] = float(value)
else:
dict[metric.get('name')] = int(value)
list.append(dict) #Append that data to a list as a dictionary
#So to recap
#You make an initial call to your function passing a pagetoken to get it started.
#Get the nextPageToken), process the data and append to list
#If there is data in the nextPageToken call the function, process, add to list until nextPageToken is empty