Can GoogleAdService Query Pagination support fetching a specific page?

521 views
Skip to first unread message

Zhong Li

unread,
Jan 7, 2022, 12:07:21 AM1/7/22
to AdWords API and Google Ads API Forum
In the old AdWords API, the SelectorBuilder can specify offset/limit to fetch a specified page of entity results(https://ads-developers.googleblog.com/2014/02/adwords-api-java-selector-builder.html). 

For example, if my campaign has 2000 ads, I want to list the ads from 501 to 600, then I make the  SelectorBuilder builder = new SelectorBuilder() .fields("Id", "Name") .orderAscBy("Id") .offset(500) .limit(100) .build()

But in the GoogleAds API, the  GoogleAdsService.SearchStream would return a stream of all results. To get a custom page (with specified offset), we need to manually read the stream and handle it on client side; If we use GoogleAdsService.Search, then it does not support "offset" but can only specify the pageSize, so we still need iterate the pages and calculate the "desired page of results".

May I ask if there's a better way to achieve this? or any equivalent solution in GoogleAds API as the AdWords API's SelectorBuilder.

Thanks!

Google Ads API Forum Advisor

unread,
Jan 7, 2022, 2:28:46 AM1/7/22
to charl...@gmail.com, adwor...@googlegroups.com

Hi,

Thanks for reaching out to us.

Note that LIMIT with offset is not supported in GAQL. An equivalent way to achieve this using pagination. The pagination uses pageSize by specifying page_size in your request. This will break up the result set of the query into multiple responses that each contain up to page_size objects. If page_size is not specified, it is automatically set to the maximum page size of 10,000 rows.

Suppose if your account contains 50,000 keywords and page_size is set to 1,000, the result set will contain 1,000 GoogleAdsRow objects in the first response, along with a next_page_token. To retrieve the next one thousand rows, simply send the request again with the same page size, but update the request's page_token to the response's next_page_token. The value of page_size in the subsequent requests can be different each time. The next_page_token will not be populated on the response that contains the last batch of rows. For more information on paging, you may refer to this guide. Let us know if you have any further questions.

Regards,

Google Logo
Yasar
Google Ads API Team
 


ref:_00D1U1174p._5004Q2UhT68:ref

Zhong Li

unread,
Jan 7, 2022, 2:42:48 AM1/7/22
to AdWords API and Google Ads API Forum
Thanks for replying. I knew the usage of  page_size but it's not convenient if we want to get a specific range with variable start index.

Hope Goolgle consider to add the offset support in GAQL, anyways... thanks again!

Google Ads API Forum Advisor

unread,
Jan 7, 2022, 4:21:36 AM1/7/22
to charl...@gmail.com, adwor...@googlegroups.com
Hi Zhong,

Thank you for the reply.

Allow me to raise a feature request to my team about the pagination that you are looking for in the report, subject for review. For now, please follow our blog as we will post relevant updates when it become support.

Regards,
Google Logo
Ernie John Blanca Tacata
Google Ads API Team
 


ref:_00D1U1174p._5004Q2UhT68:ref
Reply all
Reply to author
Forward
0 new messages