Authenticate Javascript Program for Gcloud AutoML Vision API

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Authenticate Javascript Program for Gcloud AutoML Vision API



I am currently working on a project whereby I have used gcloud automl to train an image classifier. I have got it working fine and it is able to handle my requests using access-tokens. However, my issue lies in that access-tokens only last for an hour. I would like to be able to create a method in my client-side javascript or another way to authenticate such that it is indefinite and I do not need to manually generate new tokens.



I have looked through the samples and docs on gcloud and found a sample that describes a possibility with the People API but I am not sure how to translate this to the Vision API.



Currently I am sending a request like the following:


$.ajax(
url: "https://automl.googleapis.com/v1beta1/projects/(project-id)/locations/us-central1/models/(model-id):predict",
beforeSend: function(xhr)
xhr.setRequestHeader("Authorization", "Bearer " + "access-token");
,
type: 'POST',
dataType: 'json',
contentType: 'application/json',
processData: false,
data: objString,
success: function (data)
alert(JSON.stringify(data));
,
error: function()
alert("Cannot get data");

);



If there is a way to alter this method (or write a new one) to make a permanent token or another authentication form that is indefinite, then that would be much appreciated.




1 Answer
1



You should use an environment variable along with a service account. Depending on your OS, you could use it until you turn off your machine, or set it as a permanent environment variable.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

Firebase Auth - with Email and Password - Check user already registered