我正在尝试创建一个使用 google translate api 的 Node.js 代码。我从 google doc ( https://cloud.google.com/translate/docs/translating-text )得到以下代码
但是当我运行它时,它说“错误:请求缺少有效的 API 密钥。” 我有钥匙,但我不知道如何以及在哪里设置它。
async function translate() { // Imports the Google Cloud client library
const { Translate } = require('@google-cloud/translate');
// Creates a client
const translate = new Translate();
/**
* TODO(developer): Uncomment the following lines before running the sample.
*/
const text = 'Hello, world!';
const target = 'ru';
// Translates the text into the target language. "text" can be a string for
// translating a …Run Code Online (Sandbox Code Playgroud)