c# - 方法 'ImageAnnotatorClient.Create' 没有重载需要 1 个参数

标签 c# google-cloud-platform google-cloud-vision google-client

我正在使用 Google.Cloud.Vision.V1, Version=2.0.0.0 和以下来自 Google Vision API specify JSON file 的代码

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

我在文档中找到了类似的代码 https://googleapis.github.io/google-cloud-dotnet/docs/Google.Cloud.Vision.V1P2Beta1/api/Google.Cloud.Vision.V1P2Beta1.ImageAnnotatorClient.html

但由于某些原因,它不起作用(无法看到过载)

最佳答案

看来您正在使用较新版本的 API。 Docs声明现在通过环境变量设置身份验证(需要时):

Otherwise, the simplest way of authenticating your API calls is to download a service account JSON file then set the GOOGLE_APPLICATION_CREDENTIALS environment variable to refer to it. The credentials will automatically be used to authenticate. See the Getting Started With Authentication guide for more details.

所以你可以这样做:

 Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "PathTo_VisionProject.json");
 var client = ImageAnnotatorClient.Create();

或者以其他方式设置这个环境变量。

关于c# - 方法 'ImageAnnotatorClient.Create' 没有重载需要 1 个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61853374/

相关文章:

c# - MEF - 我是否需要实现 IPartImportsSatisfiedNotification

c# - 获取非显式字段偏移量

python - 错误: pip's dependency resolver does not currently take into account all the packages that are installed.数据流python自定义模板

python-3.x - 将变量传递给 Google Cloud Functions

python - Google Cloud Platform 数据流集成

google-cloud-vision - 文档中的 Cloud Vision API 限制是否正确?

javascript - 在 JavaScript 中转义 dotnet 资源

c# - 有没有办法直观地划分组合框中的项目?

ocr - 谷歌云视觉API 'Request Admission Denied'

python - 使用gunicorn+Flask时Google Cloud Vision没有响应