0

As per the Google documentation if we use a sessiontoken in the autocomplete API followed by placeDetails api then subsequent all the calls will be grouped together and it will be billed as a single request. But while using, it is actually not happening and Google counts all of the requests as individual.

I/flutter (12295): Get URI: https://maps.googleapis.com/maps/api/place/autocomplete/json?input=s&key=<API_KEY>&sessiontoken=d7f1f97f-621d-45cf-b8fd-38d74c976fd8&location=37.4220309%2C-122.0839848&radius=5000&strictbounds=true
I/flutter (12295): Get URI: https://maps.googleapis.com/maps/api/place/autocomplete/json?input=st&key=<API_KEY>&sessiontoken=d7f1f97f-621d-45cf-b8fd-38d74c976fd8&location=37.4220309%2C-122.0839848&radius=5000&strictbounds=true
I/flutter (12295): Get URI: https://maps.googleapis.com/maps/api/place/autocomplete/json?input=sta&key=<API_KEY>&sessiontoken=d7f1f97f-621d-45cf-b8fd-38d74c976fd8&location=37.4220309%2C-122.0839848&radius=5000&strictbounds=true
I/flutter (12295): Get URI: https://maps.googleapis.com/maps/api/place/autocomplete/json?input=stat&key=<API_KEY>&sessiontoken=d7f1f97f-621d-45cf-b8fd-38d74c976fd8&location=37.4220309%2C-122.0839848&radius=5000&strictbounds=true
I/flutter (12295): Get URI: https://maps.googleapis.com/maps/api/place/autocomplete/json?input=stati&key=<API_KEY>&sessiontoken=d7f1f97f-621d-45cf-b8fd-38d74c976fd8&location=37.4220309%2C-122.0839848&radius=5000&strictbounds=true
I/flutter (12295): Get URI: https://maps.googleapis.com/maps/api/place/autocomplete/json?input=statio&key=<API_KEY>&sessiontoken=d7f1f97f-621d-45cf-b8fd-38d74c976fd8&location=37.4220309%2C-122.0839848&radius=5000&strictbounds=true
I/flutter (12295): Get URI: https://maps.googleapis.com/maps/api/place/autocomplete/json?input=station&key=<API_KEY>&sessiontoken=d7f1f97f-621d-45cf-b8fd-38d74c976fd8&location=37.4220309%2C-122.0839848&radius=5000&strictbounds=true
I/flutter (12295): Get URI: https://maps.googleapis.com/maps/api/place/details/json?place_id=ChIJr3mngX66j4ARcUF6Ln6aAmk&key=<API_KEY>&sessiontoken=d7f1f97f-621d-45cf-b8fd-38d74c976fd8
I/flutter (12295): Instance of 'PlaceDetails'

In the above scenario, based on the documentation it should have counted as a single request but in the Google console - API usage, it's showing as 9 separate requests.

Is it the right way to use sessiontoken? Am I missing something?

Edit > Added logs for two search groups with placeDetails API. The sessiontoken are being refreshed after every the place details.

I/flutter (17558): Get URI: https://maps.googleapis.com/maps/api/place/autocomplete/json?input=sta&key=<API_KEY>&sessiontoken=3dd4163e-c5aa-4504-a652-0c7861704efa&location=22.863185%2C87.3552233&radius=5000&strictbounds=true
I/flutter (17558): Get URI: https://maps.googleapis.com/maps/api/place/autocomplete/json?input=stat&key=<API_KEY>&sessiontoken=3dd4163e-c5aa-4504-a652-0c7861704efa&location=22.863185%2C87.3552233&radius=5000&strictbounds=true
I/flutter (17558): Get URI: https://maps.googleapis.com/maps/api/place/autocomplete/json?input=station&key=<API_KEY>&sessiontoken=3dd4163e-c5aa-4504-a652-0c7861704efa&location=22.863185%2C87.3552233&radius=5000&strictbounds=true
I/flutter (17558): Get URI: https://maps.googleapis.com/maps/api/place/details/json?place_id=<PLACE_DETAILS>&key=<API_KEY>&sessiontoken=3dd4163e-c5aa-4504-a652-0c7861704efa
I/flutter (17558): Instance of 'PlaceDetails'
I/flutter (17558): Get URI: https://maps.googleapis.com/maps/api/place/autocomplete/json?input=sch&key=<API_KEY>&sessiontoken=a204cfe5-0824-4e2c-8fe6-5382ef542e76&location=22.863185%2C87.3552233&radius=5000&strictbounds=true
I/flutter (17558): Get URI: https://maps.googleapis.com/maps/api/place/autocomplete/json?input=scho&key=<API_KEY>&sessiontoken=a204cfe5-0824-4e2c-8fe6-5382ef542e76&location=22.863185%2C87.3552233&radius=5000&strictbounds=true
I/flutter (17558): Get URI: https://maps.googleapis.com/maps/api/place/autocomplete/json?input=schoo&key=<API_KEY>&sessiontoken=a204cfe5-0824-4e2c-8fe6-5382ef542e76&location=22.863185%2C87.3552233&radius=5000&strictbounds=true
I/flutter (17558): Get URI: https://maps.googleapis.com/maps/api/place/autocomplete/json?input=school&key=<API_KEY>&sessiontoken=a204cfe5-0824-4e2c-8fe6-5382ef542e76&location=22.863185%2C87.3552233&radius=5000&strictbounds=true
I/flutter (17558): Get URI: https://maps.googleapis.com/maps/api/place/details/json?place_id=<PLACE_DETAILS>&key=<API_KEY>&sessiontoken=a204cfe5-0824-4e2c-8fe6-5382ef542e76
I/flutter (17558): Instance of 'PlaceDetails'
Tapas Pal
  • 7,073
  • 8
  • 39
  • 86
  • Even after adding bounty, this question didn't get enough attention. – Tapas Pal Jul 18 '22 at 16:15
  • Just to confirm you are changing your session token to a new unique one once a place is returned? might be useful seeing multiple calls to the api to confirm – Rokas Rudys Jul 18 '22 at 18:10
  • 1
    after every placeDetails api call, I am changing the sessiontoken – Tapas Pal Jul 18 '22 at 18:18
  • @RokasRudys updated the question with multiple calls. – Tapas Pal Jul 18 '22 at 18:27
  • Hi, I’m not 100% sure on this but looks like to me specifying location and radius might make it a nearby search result which does not have sessiontoken https://developers.google.com/maps/documentation/javascript/places#place_search_requests if functionally feasible possible try removing those and see if the api charges change? Sorry couldn’t be much of help I’ve only previously used text base search best of luck – Rokas Rudys Jul 18 '22 at 18:43
  • 1
    What details do you need from the `placeDetails` calls? Might be worth reading the [optimization guide](https://developers.google.com/maps/documentation/places/web-service/autocomplete#cost_best_practices). – MrUpsidown Jul 19 '22 at 09:23
  • The above guide mentions that you should be specifying fields when doing the place details call, but I am doubtful that this has an impact on the use of the session token and/or the billing process. When you say every request is billed separately, can you see whether it says "per session" or "per character/request"? It looks to me that you are doing things correctly. – MrUpsidown Jul 19 '22 at 09:44
  • @MrUpsidown It was worth reading the optimization guide. However, as per the current need, we need to go for a session based on `placeDetails`. I will get more clarity once this month's bill generates as of now based on the last cost report it seems to be more than what we have calculated (session based). But the bill is coming close when we are counting each request separately. – Tapas Pal Jul 19 '22 at 16:32
  • The bounty is going to expire soon. :( – Tapas Pal Jul 23 '22 at 15:11

0 Answers0