代码之家  ›  专栏  ›  技术社区  ›  Thomas

Google Cloud Vision API-创建Grpc.Core.Channel时出错

  •  0
  • Thomas  · 技术社区  · 7 年前

    https://googleapis.github.io/google-cloud-dotnet/docs/Google.Cloud.Vision.V1/api/Google.Cloud.Vision.V1.ImageAnnotatorClient.html

    创建(ServiceEndpoint、ImageAnnotatorSetting)

    “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());
    

    有什么提示吗?

    1 回复  |  直到 7 年前
        1
  •  5
  •   Jon Skeet    7 年前

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

    using Grpc.Auth;
    

    here 定义 ToChannelCredentials 作为一种扩展方法。

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