How long do the new Places API session tokens last?

10,293

Solution 1

As far as I can see there is no official documentation regarding session duration for Places API in Google Maps Platform. I can share some information about sessions obtained from the technical support, however, it doesn't provide exact value for session duration and it looks like Google won't reveal the exact value.

First of all, if you use the built-in Autocomplete widget of Maps JavaScript API, it generates sessions for you automatically, so no need to worry about it.

If you create your own widget, you should be aware that sessions do not last very long. An autocomplete session includes some Autocomplete requests (to retrieve suggestions on a place as the user types), and at most one Places Details request (to retrieve details about the place selected by the user).

The same session token is passed to the Autocomplete and the subsequent Place Detail request.

A session starts with the first Autocomplete request (which typically happens when the user starts typing). Typically, a Places Details call is made after the user has selected one of the Autocomplete suggestions.

After a user has selected a place (for example, a Places Details call is made), a new session must be started, with a new session token.

A session token cannot be used for more than one user session. If a token is reused, the session will be considered invalid and the requests will be charged as if no session token was provided.

If session token is expired or invalidated you will be charged on the per keystroke basis. So each autocomplete request will be charged.

I hope you find this information useful.

Solution 2

As a customer of Google Maps, when we contacted their support team, an agent that worked with us told us that the timeout is 3 minutes.

Share:
10,293
jbhelfrich
Author by

jbhelfrich

Updated on July 08, 2022

Comments

  • jbhelfrich
    jbhelfrich almost 2 years

    I have a website that uses address autocomplete on multiple pages--address book, shipping address, billing address. With the billing changes releasing next month, we can convert the Autocomplete process to use sessions instead of individual keystrokes. (https://cloud.google.com/maps-platform/user-guide/pricing-changes/#billing-changes)

    • How long is an AutocompleteSessionToken good for? The current page? An hour? Twelve? Permanently, with it counting against the limit each time it shows up in a new month?
    • If a session token does expire, and we send that token with a request, what's the result going to be? If the customer leaves a webpage open for a day and comes back to pick up, and our session data hasn't expired, how do we make sure they don't get autocomplete errors?
  • James
    James almost 6 years
    Can you expand on this f you use the built-in Autocomplete widget of Maps JavaScript API, it generates sessions for you automatically, what clasifies as the built in one? As in put a dynamic map on the page that has a search box in the map?
  • xomena
    xomena almost 6 years
    Built-in widgets are google.maps.places.Autocomplete and google.maps.places.SearchBox. They will generate session tokens for you automatically. If you use google.maps.places.AutocompleteService, you should create session tokens yourself. Have a look at example of session token in cloud.google.com/maps-platform/user-guide/pricing-changes
  • Mahesh Bongani
    Mahesh Bongani over 5 years
    @xomena I see the Google API widgets are not generating same tokens per session, instead, a different token is generated for every request. Please help. stackoverflow.com/questions/51728344/…
  • Michael
    Michael over 5 years
    @xomena I am using the sessiontoken in my autocomplete and details request but I get charged for the Autocomplete without Place Details SKU. Any ideas?
  • xomena
    xomena over 5 years
    @Michael Do you execute place details request after autocomplete? Do you pass the same session token to place details? Do you change session token once you requested a detailed information?
  • Michael
    Michael over 5 years
    @xomena yes, yes and yes. I execute a couple or more autocomplete requests with token ASD and then when the user selects a place I do a details request with token ASD. After that a new session token is generated. The parameter name I am using is sessiontoken for both and place_id for the details request. Also, I don't see any feedback in the API response about the session token.
  • xomena
    xomena over 5 years
    @Michael In this case try to contact technical support team via console.cloud.google.com/google/maps-apis/support. They should be able to figure out what is happening based on their internal logs.
  • TheIT
    TheIT almost 5 years
    I just wanted to add that the official documentation states within a few minutes of the beginning of the session, so the 3 minutes you were quoted may change over time developers.google.com/places/android-sdk/…
  • Ardy Febriansyah
    Ardy Febriansyah about 3 years
    What if user cancel the session (user not tap the suggestion) and try different keyword ? should create new token for new keyword ?
  • Richard Scarrott
    Richard Scarrott over 2 years
    How on earth are you supposed to know when to create a new session token if the user didn't choose a prediction!? I assumed you'd have to create a ttl and change it once this is passed but if they don't disclose this information then how can it work?
  • devuxer
    devuxer about 2 years
    @riscarrott, My thoughts exactly. This is simply a bad API. A user could start looking something up, get distracted, come back five minutes later and make a selection. If you don't refresh your token after a timeout period, every keystroke following the distraction would get charged. A better API would be to end a session when a place details lookup occurs (enforced by allowing the token to be part of the details lookup payload).