【问题标题】:Google Vision API not working Grpc.Core.RpcExceptionGoogle Vision API 不工作 Grpc.Core.RpcException
【发布时间】:2019-09-20 19:59:11
【问题描述】:

我正在尝试让 Google Vision API 与我的项目一起使用,但遇到了问题。我不断收到以下错误:

Grpc.Core.RpcException: 'Status(StatusCode=PermissionDenied, Detail="此 API 方法需要启用计费

我创建了一个服务帐户,启用了计费功能,并且我拥有 .json 文件。我的 GOOGLE_APPLICATION_CREDENTIALS 帐户的环境变量指向 .json 文件。

我尚未使用 Google 文档或查看 StackOverFlow 找到解决问题的方法。

using Google.Cloud.Vision.V1;
using System;
using System.Collections.Generic;

namespace Vision
{
    internal static class GoogleVision
    {
        public static EntityAnnotation[] GetAnnotations(EventManager em, string filePath, string EventNr)
        {
            {
                ImageAnnotatorClient Client = ImageAnnotatorClient.Create();
                Image Image = Google.Cloud.Vision.V1.Image.FromFile(filePath);
                IReadOnlyList<EntityAnnotation> Response = Client.DetectLabels(Image);

                EntityAnnotation[] annotations = new EntityAnnotation[Response.Count];
                for (int i = 0; i < annotations.Length; i++)
                {
                    annotations[i] = Response[i];
                }

                return annotations;
            }
        }
    }
}

【问题讨论】:

    标签: c# windows visual-studio google-api environment-variables


    【解决方案1】:

    不知道为什么,但是通过在代码中设置环境变量而不是在 windows 中手动设置,它解决了问题。

    Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "thejsonfile");
    

    【讨论】:

      猜你喜欢
      • 2019-05-11
      • 2021-03-01
      • 2018-05-14
      • 2017-07-07
      • 1970-01-01
      • 1970-01-01
      • 2016-06-10
      • 1970-01-01
      • 2021-01-17
      相关资源
      最近更新 更多