How long do the new Places API session tokens last? - google-maps

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?

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.

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.

Related

Get User's first and last name via Google API

Currently I am developing a Chrome-GMAIL extension which requires me to get the logged in user's first and last names. For experimentation, I have used the following goggle API (userinfo) and have successfully obtained the names I wanted:
https://www.googleapis.com/auth/userinfo.profile
However, using the userinfo APIs will cause a change in the OAuth2 scopes in my manifest. This change will in turn cause a permission-prompt to my existing users (if a domain wide delegation is not setup in place). Point being the idea of having more prompts in front of my user, or additional oauth scope is not really something I desire.
Currently our extensions use the following OAuth scopes and API :
Chrome's Identity API
Chrome's Storage API
GMAIL.modify
GMAIL.send
My question is, is it possible to get the first and last names using an API that is defined/allowed/provided for by any of the above scopes/permissions I listed? or is userinfo the only way to go?
Thank you very much.
Profile data like first name and last name is private data. You are corect that some Google apis give you access to some data that would normally require an extra scope. For email normally you would need to to request the email scope to get this back however the Gmail api does have an endpoint getprofile which will return the current users email address without you requesting the email scope.
However i am not aware of any apis that will give you access to the users first and last name without you requesting the profile or user.profile scope.
If you do decide to add the scope, I do recommend going though the people api rather then the userinfo endpoint as the data returned by the user info endpoint is not guaranteed to always return the name.

How to know if sessionToken was implemented properly?

So I'm trying to implement a simple location autocompletion with the google places api. I'm using the autocomplete service for this (see: https://developers.google.com/maps/documentation/javascript/reference/places-autocomplete-service).
What I'm doing right now is, creating an autocomplete token and renewing it if either 3 Minutes ran out (according to How long do the new Places API session tokens last?) or a place detail request was set (according to https://developers.google.com/places/web-service/session-tokens).
Now, I want to debug this and want to know if I did it properly.The dashboard on the google developer console counts every single request made though.
How do I know if it has an effect?|
If you implemented session tokens correctly in your application, in your billing report within the Google Cloud Platform Console you should see one or both of the following SKUs:
Autocomplete without Places Details – Per Session Autocomplete
(included with Places Details) – Per Session
If you didn't, you'll see this instead:
Autocomplete – Per Request
Note that this only applies if you use getPlacePredictions(). There are no session tokens for getQueryPredictions().
Hope this helps!

How to deal with Sessions in the new Places API Billing?

The new Places API Billing defines Sessions for merging Autocomplete and Place details requests, but the docs just say the API will merge requests with the same Session Token, made within some minutes.
I find this very vague!
Do we have to generate new Session Tokens or can we reuse the same and the API will group them anyway within time-windows?
Do we have to be aware of the lifespan of the Session Tokens?
Can the Session Tokens be any kind of string?
Google has all this answers, but is spread over a lot of different places and can be hard to find. To answer all 3 of your questions:
Do we have to generate new Session Tokens or can we reuse the same and the API will group them anyway within time-windows?
The session tokens cannot be reused from one session to the other.
Do we have to be aware of the lifespan of the Session Tokens?
The session begins when the user starts typing and ends when they select a place and you call the detail API. Once that happens you must generate a new session token for each new call to the autocomplete API.
Can the Session Tokens be any kind of string?
The Google Places API provides a class that you can use, but you don't have to. The class Google provides is called AutocompleteSessionToken it can be used liked this:
var token = new google.maps.places.AutocompleteSessionToken()
But you can also use your own string. See Google's recommendation
All this info is straight from the Google Docs, see below:
Place Autocomplete uses session tokens to group the query and selection phases of a user autocomplete search into a discrete session for billing purposes. The session begins when the user starts typing a query, and concludes when they select a place. Each session can have multiple queries, followed by one place selection. Once a session has concluded, the token is no longer valid; your app must generate a fresh token for each session. We recommend using session tokens for all autocomplete sessions. 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).
Source: Google Documentation

What does Google mean by "user" in Maps Time Zone API quota?

Looking at the Time Zone API quota limit option that says:
"Requests per 100 seconds per user"
Was trying to find a clear definition of user but to no avail.
My intuitive guess it's an IP address... yet would like to avoid unpleasant surprises.
Would be good to know what does user mean exactly. Any ideas?
I believe this is a confusion that comes from the fact that Google Maps APIs share the same developer console with Google Cloud Platform. The "Requests per 100 seconds per user" make sense in Google Cloud Platform, but I don't think they are really supported in Google Maps APIs.
If we check the documentation of Google Cloud Platform we will see the following explanation
To prevent individual users from using up your API quota, limit the number of requests per second per user for an API. Each API includes a default per-user limit, but you can modify that value as described in the previous section.
Individual users are identified by a unique string; if you're creating a server-side application (where the calling code is hosted on a server that you own) that makes requests on behalf of users, your requests must include the quotaUser parameter, as described below.
To identify a user, use the quotaUser=userID parameter. This value is for short term quota enforcement only, so you don't need to use a real user ID. You can choose any arbitrary string under forty characters long that uniquely identifies a user.
The quotaUser parameter is only used for capping requests per user per second. If you don't send the quotaUser parameter, then all calls are attributed to your server machines, in which case calls can't be capped by user.
source: https://cloud.google.com/apis/docs/capping-api-usage#limiting_requests_per_second_per_user
As far as I know none of Google Maps APIs support a quotaUser parameter, so this value doesn't make sense for Google Maps web services and as mentioned in the last paragraph Google Maps web services will attribute usage to server machines. In other words to IP addresses of your backend servers.
I hope this clarifies your doubt.

How google autocomplete limits works?

I'm using Google autocomplete on my site.
I read that: Applications that submit requests with an API key are allowed 1 000 requests per 24 hour period.
Today 100 people have submitted the autocomplete form, how the daily request quota for the API been exceeded?
When users are typing a text in the autocomplete element each new symbol in the text input will trigger requests similar to
https://maps.googleapis.com/maps/api/place/js/AutocompletionService.GetPredictions?parameters
When the user selects an address from the list of suggestions this might trigger another request for place details similar to
https://maps.googleapis.com/maps/api/place/js/PlaceService.GetPlaceDetails?parameters
You can see all these requests in the network activity tab of your browser as shown in my screenshot
Each autocomplete request and each place details request that you see in network activity tab consumes the Places API quota. By default it is 1000 daily requests, but you can enable billing and get 150K daily requests for Places API free of charge:
https://developers.google.com/places/web-service/usage
I hope this helps!