【发布时间】:2018-07-13 14:08:36
【问题描述】:
我正在尝试在我的 c# 项目中使用 googles vision api。我正在使用他们提供的测试代码,但由于某种原因,我的代码找不到 google_application_credentials,这是错误:
应用程序默认凭据不可用。如果在 Google Compute Engine 中运行,它们就可用。否则,必须定义环境变量 GOOGLE_APPLICATION_CREDENTIALS 指向定义凭据的文件。请参阅https://developers.google.com/accounts/docs/application-default-credentials 了解更多信息。
代码如下:
using System;
using Google.Cloud.Vision.V1;
namespace Test
{
public class Vision
{
public static void Main(String[] args)
{
// Instantiates a client
var client = ImageAnnotatorClient.Create();
// Load the image file into memory
var image = Image.FromFile("wakeupcat.jpg");
// Performs label detection on the image file
var response = client.DetectLabels(image);
foreach (var annotation in response)
{
if (annotation.Description != null)
Console.WriteLine(annotation.Description);
}
}
}
}
文档(https://cloud.google.com/vision/docs/reference/libraries) 告诉我导出环境变量 GOOGLE_APPLICATION_CREDENTIALS 这就是我所做的。但我仍然得到上面的错误。请帮忙!
【问题讨论】:
标签: c# monodevelop google-vision