我正在尝试从 AWS Lambda 函数访问 Google Cloud API,但我不知道如何进行身份验证。 Google Cloud 文档中的身份验证指南 (https://cloud.google.com/docs/authentication https://cloud.google.com/docs/authentication)希望我下载凭证 JSON 文件并使用应用程序默认凭证,但任何使用过托管函数的人都知道,重点是您不需要管理服务器或运行时环境,因此 Lambda 不给我在运行代码的环境中存储任意文件的能力。
我可以在本地使用 Cloud SDK 来获取访问令牌,但它会过期,因此我无法在我的函数中将其用作永久解决方案。
有没有办法获得可以在代码中无限期使用的访问令牌来调用 Google Cloud API?还有其他解决办法吗?
我发现了如何对凭据进行硬编码,而不需要将它们保存在 JSON 文件中。它在这个文档中:
https://googlecloudplatform.github.io/google-cloud-node/#/docs/language/0.7.0/guides/authentication https://googlecloudplatform.github.io/google-cloud-node/#/docs/language/0.7.0/guides/authentication
下面是调用语言 API 的示例。
var language = require('@google-cloud/language')({
projectId: '',
credentials: {
client_email: '',
private_key: '',
}
});
language.detectEntities('Axel Foley is from Detroit').then(function(data) {
var entities = data[0];
var apiResponse = data[1];
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)