New Google Places Autocomplete Queries Per Session

196 Views Asked by At
sessiontoken
A random string which identifies an autocomplete session for billing purposes.

The session begins when the user starts typing a query, and concludes when they select a place and a call to Place Details is made. Each session can have multiple queries, followed by one place selection. The API key(s) used for each request within a session must belong to the same Google Cloud Console project. Once a session has concluded, the token is no longer valid; your app must generate a fresh token for each session. If the sessiontoken parameter is omitted, or if you reuse a session token, the session is charged as if no session token was provided (each request is billed separately).

I am not able to understand when does the token becomes invalid? How many autocomplete queries i can make if i do not make Place Details call, or is there any time limit after which token expires?

What if i keep on passing the same session token value every time? What i mean is if the session token expires will the same token would be treated as new session token and would remain valid for the time it expires again?

Source : https://developers.google.com/maps/documentation/places/web-service/autocomplete.

1

There are 1 best solutions below

0
Yrll On

There's a dedicated Public Documentation for Session Token here:

https://developers.google.com/maps/documentation/places/web-service/session-tokens

But currently, there are no public Places API documentation regarding session token expiration. Ideally, the session begins when a user starts typing on the autocomplete and ends when they select a place from the list of suggestion.

Now with regards to your question "if the session token expires will the same token would be treated as new session token and would remain valid for the time it expires again?", the documentation says this:

"You can optionally omit the autocomplete session token from a request. If the session token is omitted, each request is billed separately, triggering the Autocomplete - Per Request SKU. If you reuse a session token, the session is considered invalid and the requests are charged as if no session token was provided."

If you are implementing Place Autocomplete programmatically, it is recommended that you do the following:

  • Use session tokens for all autocomplete sessions.
  • Generate a fresh token for each session.
  • Ensure that the API key(s) used for all Place Autocomplete and Place Details requests within a session belong to the same Google Cloud Console project.
  • Be sure to pass a unique session token for each new session. Using the same token for more than one session will result in each request being billed individually.

If you find the programmatical way confusing, i'd recommend that you use the Places Autocomplete widget because it automatically handles session tokens. You can check the sample here: https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete

I hope this helps!