Page token has expired

268 views
Skip to first unread message

Alin Alex

unread,
Jun 7, 2022, 9:43:22 AM6/7/22
to Google Ads API and AdWords API Forum
Currently we are making some search calls to googleads using search method with python client library.
After 4 hours we get message: "Page token has expired."

We have the following questions:
Because from the logs we cannot see and the implementation of pagination is implemented directly into the python library, the error is being thrown on the iteration part or when we try to grab the next token?


- INFO: Request made: ClientCustomerId: 606852287

Google Ads API Forum Advisor

unread,
Jun 7, 2022, 10:07:05 AM6/7/22
to alinal...@gmail.com, adwor...@googlegroups.com
Hi Alin,

Thank you for reaching out to us.

Please note that Page token has expired error indicates that the token used to retrieve a page of results from a search request has expired.

Specifically when you make a search request in Python an iterator is returned that, under the hood, makes multiple requests to the API as you iterate over it. Each request retrieves a "page" of results, the size of which is defined by the page_size parameter seen here .

If you submit a request that generates 10,000 rows and the page_size is set to 1,000 then the iterator will end up making 10 requests, each for 1,000 rows at a time.

The first response for rows 1 - 1,000 will include a page token that gets passed back to the API so it knows to retrieve rows 1,001 - 2,000, (this is all handled implicitly by the iterator).

In addition, those page tokens have a life span of two hours. If you try to grab the next token after life span, then you might get that error. For example if you submitted a request for a report with a page_size of 10,000 with a process that spent roughly 84 seconds processing each row the page token could expire by the time the next page was requested.

Best regards,
Google Logo
Heidi
Google Ads API Team
 


ref:_00D1U1174p._5004Q2bd4dK:ref

Alin Alex

unread,
Jun 7, 2022, 10:21:04 AM6/7/22
to Google Ads API and AdWords API Forum
Hello, thank you for the response but

As we can see in the logs that I've provided, those logs are coming from the client library itself and are not altered by us by any means, we have a page size of 1000 and the time between each request is likely 3-6 minutes. I do not think is because of the processing time, because every run is failing after 4 hours.
You do not think is another timeout issue with another API component?

Google Ads API Forum Advisor

unread,
Jun 7, 2022, 2:41:23 PM6/7/22
to alinal...@gmail.com, adwor...@googlegroups.com
Hi Alin,

Is it possible for you to use the SearchStream method instead of Search? If you do not require paginated results, the SearchStream method will work better as the entire result is cached in a data buffer. Please see this page on streaming for more details on Search/SearchStream. In general, we recommend using SearchStream whenever possible. 

Additionally, you may try breaking your report up into smaller date ranges, or use fewer fields in your report, if possible.

Regards,
Matt
Google Ads API Team

Google Logo
Matt
Google Ads API Team
 


ref:_00D1U1174p._5004Q2bd4dK:ref

Alin Alex

unread,
Jun 8, 2022, 4:49:14 AM6/8/22
to Google Ads API and AdWords API Forum
We fall back to pagination because on the search stream we encountered another error with the message "connection reset by peer", and now we end up in this token invalidation.

Google Ads API Forum Advisor

unread,
Jun 8, 2022, 9:32:56 AM6/8/22
to alinal...@gmail.com, adwor...@googlegroups.com
Hi Alin,

Thank you for the reply.

As for the "Connection reset by peer" error, this issue appears to be client library specific. With this, I am afraid that our team would not be able to provide support here as it is outside of our scope already. I would suggest reaching out to the author of the client library instead via this link as they are more equipped here and provide insights to address the issue.

Best regards,
Google Logo
Heidi
Google Ads API Team
 


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