c# - 方法“ImageAnnotatorClient.Create”没有重载需要 1 个参数
问题描述
我正在使用Google.Cloud.Vision.V1, Version=2.0.0.0
以下来自Google Vision API 的代码指定 JSON 文件
using Google.Apis.Auth.OAuth2;
using Google.Cloud.Vision.V1;
using Grpc.Auth;
using Grpc.Core;
var credential = GoogleCredential.FromFile("VisionProject.json");
var channel = new Grpc.Core.Channel(ImageAnnotatorClient.DefaultEndpoint.ToString(), credential.ToChannelCredentials());
var client = ImageAnnotatorClient.Create(channel);
但它向我展示了这个错误No overload for method 'ImageAnnotatorClient.Create' takes 1 arguments
。
但由于某种原因,它不起作用(无法看到过载)
解决方案
看来您正在使用更新版本的 API。文档状态现在通过环境变量设置身份验证(在需要时):
否则,验证 API 调用的最简单方法是下载服务帐户 JSON 文件,然后设置 GOOGLE_APPLICATION_CREDENTIALS 环境变量以引用它。凭据将自动用于身份验证。有关更多详细信息,请参阅《身份验证入门》指南。
所以你可以做这样的事情:
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "PathTo_VisionProject.json");
var client = ImageAnnotatorClient.Create();
或者以其他方式设置此环境变量。
推荐阅读
- ansible - 基于 ansible stdout 值的回显消息
- python - 我可以根据同一位置的值在 folium 中添加标记吗?
- c# - SignalR 错误错误:由于服务器上的错误,无法调用“方法名”
- model-view-controller - 在 MVC .NET Core 中使用后退按钮时没有刷新页面
- javascript - 按端点请求格式化数据集
- python - django,检查对象是否是查询集的一部分,没有返回正确的值
- azure - 获取 terraform 中可能的出站 IP 地址列表
- python - 如何在使用请求抓取时绕过 Google Recaptcha
- python - 使用 Google Cloud automl 中的 saved_model.pb 在 Python 中进行本地预测
- xamarin.forms - 无法在按钮单击中动态更改属性值