Setting Max Results in API v4 (python)

2024/10/9 11:25:00

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. I haven't been able to figure out how to pass that parameter in v4 of the API using python.

My code looks something like below. I've commented out my best guess at 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()
Answer

The correct name of the parameter you are looking for is: pageSize. The Reference Docs provide the full API specifications.

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. 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.

Stack Overflow extra tip. Include your error responses in your question, as it will likely improve your chances of someone being able to help.

https://en.xdnf.cn/q/70024.html

Related Q&A

Extract text between two different tags beautiful soup

Im trying to extract the text content of the article from this web page.Im just trying to extract the article content and not the "About the author part".The problem is that all the content a…

Add column to pandas without headers

How does one append a column of constant values to a pandas dataframe without headers? I want to append the column at the end.With headers I can do it this way:df[new] = pd.Series([0 for x in range(le…

Replace NaN values of pandas.DataFrame with values from list

In a python script using the library pandas, I have a dataset of lets say 100 lines with a feature "X", containing 36 NaN values, and a list of size 36.I want to replace all the 36 missing va…

Boring Factorials in python

I am trying to understand and solve the following problem :Sameer and Arpit want to overcome their fear of Maths and so they have been recently practicing Maths problems a lot. Aman, their friendhas be…

The flask host adress in docker run

I want to run a flask application in Docker, with the flask simple http server. (Not gunicorn)I got a host setting problem. In the flask app.py, it should be work as the official tutorial, but it doesn…

Extracting text from pdf using Python and Pypdf2

I want to extract text from pdf file using Python and PYPDF package. This is my pdf fie and this is my code:import PyPDF2 opened_pdf = PyPDF2.PdfFileReader(test.pdf, rb)p=opened_pdf.getPage(0)p_text= p…

Is it possible to change turtles pen stroke?

I need to draw a bar graph using Pythons turtle graphics and I figured it would be easier to simply make the pen a thick square so I could draw the bars like that and not have to worry about making doz…

How to make a local Pypi mirror without internet access and with search available?

Im trying to make a complete local Pypi repository mirror with pip search feature on a server I can only connect an external hard drive to. To be clear, I dont want a simple caching system, the server …

Turn an application or script into a shell command

When I want to run my python applications from commandline (under ubuntu) I have to be in the directory where is the source code app.py and run the application with commandpython app.pyHow can I make i…

pytest - monkeypatch keyword argument default

Id like to test the default behavior of a function. I have the following:# app/foo.py DEFAULT_VALUE = hellodef bar(text=DEFAULT_VALUE):print(text)# test/test_app.py import appdef test_app(monkeypatch):…