Using sessiontoken in Google Places API and flutter

  Kiến thức lập trình

I am using the Places API to fetch information about certain cities in my app.
Everything is working fine so far except for the billing view. I also use dio for the http requests.

Here is how I add the sessiontoken to my requests:

@Riverpod(keepAlive: true)
SessionTokenInterceptor sessionTokenInterceptor(
  SessionTokenInterceptorRef ref,
) {
  return SessionTokenInterceptor(ref);
}

class SessionTokenInterceptor extends QueuedInterceptor {
  SessionTokenInterceptor(this.ref);

  final SessionTokenInterceptorRef ref;

  @override
  void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
    final withSessionToken =
        options.extra[GoogleMapApiConfig.withSessionTokenExtraKey];
    if (withSessionToken != null) {
      options.headers[GoogleMapApiConfig.sessionTokenHeaderKey] =
          ref.read(sessionTokenProvider);
    }
    return handler.next(options);
  }
}

Via debugging I can see that the same token is used as well for place autocomplete as for place details, but I wonder if adding the sessiontoken as header instead of query parameter is recommended. The code is basically from https://github.com/AhmedLSayed9/deliverzler.

I asked the question because the documentation (SKU: Autocomplete (included with Place Details) – Per Session) states that when using sessiontoken, I should see something like

Autocomplete (included with Place Details

Place Details (price starting at 0.017 USD per session)

But I cannot see anything like that. I rather see

Autocomplete – Per Request

Place Details

and my bill is increasing really fast. Luckily I am still in the test phase.
I don’t know if my sessiontoken is being considered at all.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT