且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在没有Application Default Credentials或Cloud SDK的情况下向Google Cloud API进行身份验证?

更新时间:2023-09-10 16:11:34

我发现如何对凭证进行硬编码,而无需将其保存在JSON文件中。这是在这里的文档:

I found how to hard-code the credentials without the need to save them in a JSON file. It was in this documentation here:

https://googlecloudplatform.github.io/google-cloud-node/#/docs/language/0.7.0/guides/authentication

下面是一个调用Language API的示例。

Below is an example that calls the Language 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];
});