我正在LabVIEW中访问谷歌翻译API(Google.Cloud.Translation.V2.dll)的.NET DLL,并尝试通过命令提示符设置“GOOGLE_APPLICATION_CREDENTIALS”,如谷歌关于如何设置一切的示例所示让翻译 API 工作。它似乎不起作用,当我运行我的代码时,我收到“缺少有效的 API 密钥”错误 (403)。我想我需要以编程方式设置密钥,但我无法在任何地方找到任何关于如何以编程方式设置 API 密钥的文档或示例。下面是我在尝试将一些德语文本翻译成英语时收到的 .NET 错误。
Google.GoogleApiException: Google.Apis.Requests.RequestError
The request is missing a valid API key. [403]
Errors [
Message[The request is missing a valid API key.] Location[ - ] Reason[forbidden] Domain[global]
]
我是否需要访问不同的 DLL 来设置 API 密钥?我下载了所有这些(因为它们是依赖项,我不确定在 LabVIEW 中访问 Google API 时我需要什么)并查看了我可以在所有这些中使用的潜在方法。它们是:
Google.Cloud.Translation.V2.dll、Google.Apis.Translate.v2.dll、Google.Api.Gax.dll、Google.Api.Gax.Rest.dll、Google.Apis.Auth.dll、Google.Apis。 Auth.PlatformServices.dll、Google.Apis.Core.dll、Google.Apis.dll、Google.Apis.PlatformServices.dll、Newtonsoft.Json.dll、System.Interactive.Async.dll