首页 > 解决方案 > 使用 google Cloud Vision API 的运输应用程序

问题描述

Google 使用存储在本地机器中的 JSON 文件验证对其 Cloud API 的请求。我需要设置 JSON 文件的路径以使用该库

 System.Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", @"C:\Users\admin\Downloads\vision.json");

因此,如果我要发送应用程序,是否也需要发送 JSON?不会带来安全风险吗?

更新 1:

 System.Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", @"vision.json");
 client = ImageAnnotatorClient.Create();

更新 2:

我正在使用下面的代码从文件创建凭据。我打算加密这个 JSON 文件;将其托管在服务器中。下载它,在客户端对其进行解密并从中创建凭据。

我的问题是没有将 JSON 本地存储在磁盘中,我可以将它存储在内存中并从中创建凭证吗?

var credential = GoogleCredential.FromFile("vision.json").CreateScoped(ImageAnnotatorClient.DefaultScopes);
var channel = new Grpc.Core.Channel(
ImageAnnotatorClient.DefaultEndpoint.ToString(),
credential.ToChannelCredentials());
client = ImageAnnotatorClient.Create(channel);

标签: c#.netgoogle-cloud-platformgoogle-cloud-visiongoogle-vision

解决方案


推荐阅读