Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No overload for method 'ImageAnnotatorClient.Create' takes 1 arguments

I am using Google.Cloud.Vision.V1, Version=2.0.0.0 and the following below code from Google Vision API specify JSON file

using Google.Apis.Auth.OAuth2;
using Google.Cloud.Vision.V1;
using Grpc.Auth;
using Grpc.Core;

        var credential = GoogleCredential.FromFile("VisionProject.json");
        var channel = new Grpc.Core.Channel(ImageAnnotatorClient.DefaultEndpoint.ToString(), credential.ToChannelCredentials());
        var client = ImageAnnotatorClient.Create(channel);

But its shows me this error No overload for method 'ImageAnnotatorClient.Create' takes 1 arguments.

I have found similar code in documentation https://googleapis.github.io/google-cloud-dotnet/docs/Google.Cloud.Vision.V1P2Beta1/api/Google.Cloud.Vision.V1P2Beta1.ImageAnnotatorClient.html

But for some reason, it's not working( unable to see the overload)

like image 386
Imran Qadir Baksh - Baloch Avatar asked Apr 09 '26 17:04

Imran Qadir Baksh - Baloch


2 Answers

While setting the environment variable is certainly a simple way of specifying which service account file to use, it's not the only one. You can use the builder to specify the path very easily:

var client = new ImageAnnotatorClientBuilder
{
    CredentialsPath = "VisionProject.json"
}.Build();
like image 56
Jon Skeet Avatar answered Apr 11 '26 06:04

Jon Skeet


It seems that you are using newer version of API. Docs state that now authentication is set up(when needed) via environment variable:

Otherwise, the simplest way of authenticating your API calls is to download a service account JSON file then set the GOOGLE_APPLICATION_CREDENTIALS environment variable to refer to it. The credentials will automatically be used to authenticate. See the Getting Started With Authentication guide for more details.

So you can do something like this:

 Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "PathTo_VisionProject.json");
 var client = ImageAnnotatorClient.Create();

Or set this environment variable some other way.

like image 39
Guru Stron Avatar answered Apr 11 '26 07:04

Guru Stron