【问题标题】:Google Cloud Vision API - Error creating Grpc.Core.ChannelGoogle Cloud Vision API - 创建 Grpc.Core.Channel 时出错
【发布时间】:2019-02-24 03:22:47
【问题描述】:

我正在尝试使用 Google Cloud Vision V1 Api 的 ImageAnnotatorClient 类。我正在关注https://googleapis.github.io/google-cloud-dotnet/docs/Google.Cloud.Vision.V1/api/Google.Cloud.Vision.V1.ImageAnnotatorClient.html

下的示例

创建(ServiceEndpoint, ImageAnnotatorSettings)

标题。我正在使用 C# 并尝试构建一个经典的控制台应用程序。我正在使用来自 Nuget 的 GRPC.Core 版本 1.15.0 和 Google.Cloud.Vision.V1 版本 1.2.0。我得到一个编译错误

“GoogleCredential”不包含对 'ToChannelCredentials' 并且没有扩展方法 'ToChannelCredentials' 可以找到接受“GoogleCredential”类型的第一个参数

以下是我的代码:

GoogleCredential credential = GoogleCredential
    .FromFile(@"C:\Users\...\12345.json")
    .CreateScoped(ImageAnnotatorClient.DefaultScopes);
            Google.Cloud.Vision.V1.Image image1 = Google.Cloud.Vision.V1.Image.FromFile(@"c:\Users\....\Image14b.png");

            Channel channel = new Channel(
    ImageAnnotatorClient.DefaultEndpoint.Host, ImageAnnotatorClient.DefaultEndpoint.Port, credential.ToChannelCredentials());
            ImageAnnotatorClient client = ImageAnnotatorClient.Create(channel);

            IReadOnlyList<EntityAnnotation> textAnnotations = client.DetectText(image1);

我在下面的行中收到错误:

        Channel channel = new Channel(
ImageAnnotatorClient.DefaultEndpoint.Host, ImageAnnotatorClient.DefaultEndpoint.Port, credential.ToChannelCredentials());

有什么提示吗?

【问题讨论】:

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


    【解决方案1】:

    您可能缺少使用指令之一,特别是

    using Grpc.Auth;
    

    参见hereToChannelCredentials的定义作为扩展方法。

    检查您是否也包含了示例中存在的所有其他 using 指令。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-07
      • 1970-01-01
      • 2016-06-06
      • 1970-01-01
      • 1970-01-01
      • 2020-10-22
      • 2023-03-02
      • 2019-03-13
      相关资源
      最近更新 更多