AutoML Natural Language Token

368 Views Asked by At

I'm using AutoML Natural Language API, with my custom trained model to predict results.

In order, to use this service, I generate a Authorization token through Cloud Shell, that enables api requests.

So, I configured/created the service account and add "automl.editor" rule to service account, and:

-> export GOOGLE_APPLICATION_CREDENTIALS=/home/[project id]/[json key file]

->gcloud auth application-default print-access-token

It returns a valid token that works for 1 hour.

Is there any way to get a valid token for longer time? (or do I have to generate other?)

https://automl.googleapis.com/[version]/projects/[project id]/locations/[local id]/models/[MODEL ID]:predict

Thanks.

1

There are 1 best solutions below

0
On BEST ANSWER

The 1 hour access token life time is fixed and cannot be changed. You do have to generate a new one once it expires, by either manually print it or by refresh token.

However, the print-access-token approach is for testing and debugging, when you need the quick access to Google APIs. In reality usage, you should use service account for authentication. Please follow this tutorial https://cloud.google.com/natural-language/automl/docs/tutorial, which includes the steps to setup service account.