Google Vision API не работает Grpc.Core.RpcException - PullRequest
1 голос
/ 02 мая 2019

Я пытаюсь заставить 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;
            }
        }
    }
}

1 Ответ

0 голосов
/ 02 мая 2019

Не знаю почему, но установив переменную окружения в коде, а не вручную с окнами, это решило проблему.

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