gpt4 book ai didi

c# - 如何在 C# 中设置来自 Google Cloud Vision 的 GOOGLE_APPLICATION_CREDENTIALS?

转载 作者:行者123 更新时间:2023-12-05 02:14:01 25 4
gpt4 key购买 nike

我正在关注 this tutorial使用 Google Vision API,但即使配置身份验证凭据,我也会收到以下错误:

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.'

我在 Visual Studio 2017 中的代码:

        // Instantiates a client
var client = ImageAnnotatorClient.Create();
// Load the image file into memory
var image = Google.Cloud.Vision.V1.Image.FromFile(@"C:\Users\Maicon\OneDrive\Área de Trabalho\keyboardSantander\keyboard.png");
// Performs label detection on the image file
var response = client.DetectLabels(image);
foreach (var annotation in response)
{
if (annotation.Description != null)
debugOutput(annotation.Description);
}

我该怎么做才能解决这个问题?我是否必须创建试用帐户才能使用 Google Cloud API?

最佳答案

我尝试了以上所有方法,仍然没有运气。对我有用的是通过 Environment 类中的 SetEnvironmentVariable 添加环境变量。

string credential_path = @"PATH TO GOOGLE AUTH CREDENTIAL JSON FILE";
System.Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", credential_path);

var client = ImageAnnotatorClient.Create();

var image = Image.FromFile(@"PATH TO IMAGE");

var response = client.DetectDocumentText(image);

关于c# - 如何在 C# 中设置来自 Google Cloud Vision 的 GOOGLE_APPLICATION_CREDENTIALS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54410031/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com