Using the Google Cloud Vision API with a simple API key

I am using the Google Cloud Java Vision API client described here: https://cloud.google.com/vision/docs/reference/libraries .

The following quick launch code works fine if I use the implicit default credentials by setting the GOOGLE_APPLICATION_CREDENTIALS environment variable to reference the json file for the right โ€œservice accountโ€.

// Imports the Google Cloud client library import com.google.cloud.vision.spi.v1.ImageAnnotatorClient; import com.google.cloud.vision.v1.AnnotateImageRequest; import com.google.cloud.vision.v1.AnnotateImageResponse; import com.google.cloud.vision.v1.BatchAnnotateImagesResponse; ... public class QuickstartSample { public static void main(String... args) throws Exception { // Instantiates a client ImageAnnotatorClient vision = ImageAnnotatorClient.create(); ... BatchAnnotateImagesResponse response = vision.batchAnnotateImages(requests); List<AnnotateImageResponse> responses = response.getResponsesList(); ... } } 

However, I want to authenticate to the API using a simple (single-line) API key, not a service account, and I cannot find the documentation explaining how to do this through this java library. Is it possible?

+5
source share

All Articles