0

I am trying to make one simple application in Xamrin android using Google Vision API.

What I did is,

Installed

  1. Google cloud vision v1,
  2. Google.Apis.Auth.OAuth2;
  3. Newtonsoft.Json;

in my xamarin.android project from NuGet manager.

I created

  1. API Key,
  2. Service Account,
  3. OAuth 2.0 client IDs

from google cloud console.

I created GOOGLE_APPLICATION_CREDENTIALS (Environmenta variable) and linked those Json file (both service account and OAuth 2.0 client IDs json) tried both.

Then I just copied code from google vision API documentaion.

// Load an image from a local file.
var image = Image.FromFile(filePath);
var client = ImageAnnotatorClient.Create();
var response = client.DetectLogos(image);
foreach (var annotation in response)
{
if (annotation.Description != null)
    textView.Text = (annotation.Description);
}

everytime i try to compile the program it throws exception

System.InvalidOperationException: 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 need help to set default credentials, I tried many links from google documentation but no luck. has anyone got any idea how to handle this exception.

  • what line fails and where are you creating client? – Linda Lawton - DaImTo May 02 '17 at 11:07
  • @DalmTo It stops on the var client = ImageAnnotatorClient.Create(); – Kopila Panth May 02 '17 at 11:08
  • `Google.Cloud.Vision.V1` is a gRPC-based library - even if you got past the authentication, I wouldn't expect it to work on Xamarin at the moment. Xamarin isn't a supported platform for this code, and most importantly gRPC needs a native library which is only built on x86 and x64 at the moment. – Jon Skeet May 02 '17 at 11:24
  • (It's not clear why you've added the google-app-engine tag here, either - I can't see that AppEngine is really involved here at all...) – Jon Skeet May 02 '17 at 11:25
  • @Jon Skeet Yes, your point is right, I will remove tag. Thanks for your information about xamarin support for vision api. At first, I tried it in console application and got output, so thought I can work with it in Xamarin as well. – Kopila Panth May 02 '17 at 11:37
  • 1
    We hope to support Xamarin at *some* point, but we don't right now. – Jon Skeet May 02 '17 at 11:38
  • @JonSkeet so at the moment I can't use Google.Cloud.Vision.V1 in my xamarin project. is there any alternative way to work with this api in Xamarin. – Kopila Panth May 02 '17 at 12:11
  • @KopilaPanth: You could use the REST API: https://www.nuget.org/packages/Google.Apis.Vision.v1/ – Jon Skeet May 02 '17 at 12:27
  • @JonSkeet Thank you for valuable information. Appreciated. I will search how to implement it using REST API. – Kopila Panth May 02 '17 at 13:26
  • @JonSkeet I could not find proper documentation how to work with the REST API you mentioned, could you recommend some links to me to start with that. Thanks. – Kopila Panth May 05 '17 at 01:27
  • I don't think we have samples for it, as the gRPC-based libraries are expected to be the more common route, but https://cloud.google.com/vision/docs/reference/rest/v1/images/annotate should be your starting point. See https://developers.google.com/api-client-library/dotnet/get_started for general guidance on using the REST APIs. – Jon Skeet May 05 '17 at 05:46

0 Answers0