0
votes

I am trying to use google cloud vision api text detection.

using System;
using Google.Apis.Auth.OAuth2;
using Google.Cloud.Vision.V1;
using Google.Api.Gax.Grpc;
namespace blablabla
{
    class Program
    {
        static void Main(string[] args)
        {
            string filePath = @"D:\Manisha\Pictures\1.png";

            var image = Image.FromFile(filePath);

            var client = ImageAnnotatorClient.Create();
            var response = client.DetectText(image);
            foreach (var annotation in response)
            {
                if (annotation.Description != null)
                    Console.WriteLine(annotation.Description);
            }
            Console.ReadLine();
        }
    }
}

I am getting the following error at
"var client = ImageAnnotatorClient.Create();"

"The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information."

I have set the GOOGLE_APPLICATION_CREDENTIALS to the json file path. Where am i actually going wrong. Am i missing some important steps?

1
Is the value of GOOGLE_APPLICATION_CREDENTIALS correct? Can your application access that environment variable? Does your app/Visual Studio need to be restarted? What is the value of credential? var credential = GoogleCredential.GetApplicationDefault(); - Dan Wilson
Restarting visual studio helped. Thanks. What is that line "var credential = GoogleCredential.GetApplicationDefault();" Should i add it. Is my above code wrong? - Manisha P
That appears to be a way to get an instance of the credentials, in case you wanted to test it. It's not necessary for the ImageAnnotatorClient. - Dan Wilson
@DanWilson can please make your comment into an answer? - Lefteris S

1 Answers

1
votes

There are a few things you could check in this situation.

  • Is the value of GOOGLE_APPLICATION_CREDENTIALS correct?
  • Can your application access that environment variable?
  • Does your app/Visual Studio need to be restarted?
  • What is the value of credential?

One way to check the credentials that the SDK is using is the following.

var credential = GoogleCredential.GetApplicationDefault();

This appears to be a way to get an instance of the credentials, in case you wanted to test it. It's not necessary for the ImageAnnotatorClient per se.