Manisha P
Manisha P

Reputation: 111

Google cloud vision api-authentication exception

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?

Upvotes: 0

Views: 737

Answers (1)

Dan Wilson
Dan Wilson

Reputation: 4047

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.

Upvotes: 1

Related Questions