我正在使用 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
。
但由于某些原因,它不起作用(无法看到过载)
最佳答案
看来您正在使用较新版本的 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/