C# Google Vision API不工作Grpc.Core.RpcException
我试图让谷歌视觉API与我的项目一起工作,但遇到了麻烦。我不断得到以下错误: Grpc.Core.RpcException:'状态(StatusCode=PermissionDenied,Detail=“此API方法要求启用计费 我已经创建了一个服务帐户,启用了计费,并且有了.json文件。我已经为我的GOOGLE_应用程序_凭据帐户获得了指向.json文件的环境变量 我还没有找到使用谷歌文档或检查StackOverFlow来解决问题的方法C# Google Vision API不工作Grpc.Core.RpcException,c#,windows,visual-studio,google-api,environment-variables,C#,Windows,Visual Studio,Google Api,Environment Variables,我试图让谷歌视觉API与我的项目一起工作,但遇到了麻烦。我不断得到以下错误: Grpc.Core.RpcException:'状态(StatusCode=PermissionDenied,Detail=“此API方法要求启用计费 我已经创建了一个服务帐户,启用了计费,并且有了.json文件。我已经为我的GOOGLE_应用程序_凭据帐户获得了指向.json文件的环境变量 我还没有找到使用谷歌文档或检查StackOverFlow来解决问题的方法 using Google.Cloud.Vision.V
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;
}
}
}
}
使用Google.Cloud.Vision.V1;
使用制度;
使用System.Collections.Generic;
名称空间愿景
{
内部静态类GoogleVision
{
公共静态EntityAnnotation[]GetAnnotations(EventManager em、字符串文件路径、字符串EventNr)
{
{
ImageAnnotatorClient=ImageAnnotatorClient.Create();
Image=Google.Cloud.Vision.V1.Image.FromFile(文件路径);
IReadOnlyList Response=Client.DetectLabels(图像);
EntityAnnotation[]annotations=new EntityAnnotation[Response.Count];
for(int i=0;i
不确定原因,但通过在代码中设置环境变量而不是在windows中手动设置,它解决了问题
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "thejsonfile");
不知道为什么,但是通过在代码中设置环境变量而不是在windows中手动设置,它解决了这个问题
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "thejsonfile");