gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 00:00:34 26 4
gpt4 key购买 nike

我正在使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com