Google Vision API java客户端:如何在代码中显式设置API凭据(不使用环境变量)

Google Vision API java客户端:如何在代码中显式设置API凭据(不使用环境变量),java,credentials,google-vision,explicit,client-library,Java,Credentials,Google Vision,Explicit,Client Library,我正在尝试将我的项目与 以下是maven依赖项,供您检查我尝试与之集成的客户端版本: <dependency> <groupId>com.google.cloud</groupId> <artifactId>google-cloud-vision</artifactId> <version>1.51.0</version> </dependency> 我想知道是否有一种方法可以在代

我正在尝试将我的项目与

以下是maven依赖项,供您检查我尝试与之集成的客户端版本:

<dependency>
   <groupId>com.google.cloud</groupId>
   <artifactId>google-cloud-vision</artifactId>
   <version>1.51.0</version>
</dependency>
我想知道是否有一种方法可以在代码中显式地设置凭据,因为这比在运行项目的每个环境中设置环境变量更方便

正如我所知,对于以前的客户端版本
1.22
,可以执行以下操作:

Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the 
file path of the JSON file that contains your service account key
def credentialFile = this.class.classLoader
.getResource(grailsApplication.config.credentialsFile)
GoogleCredential credential = 
GoogleCredential.fromStream(credentialFile.openStream())
        .createScoped(grailsApplication.config.googleScope)

Vision vision = new 
Vision.Builder(GoogleNetHttpTransport.newTrustedTransport(), 
jsonFactory, credential).build()
但是对于新的客户端API,我找不到方法,文档也没有说明这方面的内容。

有可能: 创建图像注释器设置,如:

ImageAnnotatorSettings ias = ImageAnnotatorSettings.newBuilder()
            .setCredentialsProvider(
                    FixedCredentialsProvider.create(#InputStream of your json key#)
            )
            .build();
把这个加到你的客户身上,瞧

有可能: 创建图像注释器设置,如:

ImageAnnotatorSettings ias = ImageAnnotatorSettings.newBuilder()
            .setCredentialsProvider(
                    FixedCredentialsProvider.create(#InputStream of your json key#)
            )
            .build();

把这个加到你的客户身上,瞧

哎呀,再也不可能了哎呀,再也不可能了