我正在尝试使Google Vision API可以与我的项目一起使用,但是遇到了麻烦。我不断收到以下错误:
Grpc.Core.RpcException:'状态(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;
}
}
}
}
答案 0 :(得分:0)
不知道为什么,但是通过在代码中设置环境变量而不是在Windows中手动设置,它解决了问题。
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "thejsonfile");