我正在尝试使用Google Vision API在Xamrin android中创建一个简单的应用程序 .

我做的是,

安装

  • 谷歌 Cloud 视觉v1,

  • Google.Apis.Auth.OAuth2;

  • Newtonsoft.Json;

在我的NuGet经理的xamarin.android项目中 .

我 Build

  • API密钥,

  • 服务帐号,

  • OAuth 2.0客户端ID

来自谷歌 Cloud 控制台 .

我创建了GOOGLE_APPLICATION_CREDENTIALS(Environmenta变量)并链接了那些Json文件(服务帐户和OAuth 2.0客户端ID json) .

然后我只是从谷歌视觉API文档复制代码 .

// 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);
}

每次我尝试编译程序时都抛出异常

System.InvalidOperationException:应用程序默认凭据不可用 . 如果在Google Compute Engine中运行,则可以使用它们 . 否则,必须定义环境变量GOOGLE_APPLICATION_CREDENTIALS,指向定义凭证的文件 . 有关详细信息,请参阅https://developers.google.com/accounts/docs/ application-default-credentials .

我需要帮助来设置默认凭据,我尝试了谷歌文档中的许多链接,但没有运气 . 有谁知道如何处理这个异常 .