无法在node.js google翻译中加载默认凭据

时间:2017-11-01 14:33:37

标签: node.js npm google-cloud-functions google-translate

我需要使用google translate翻译node.js中的一些文字。我最终得到以下错误:无法加载默认凭据。浏览到 here以获取更多详细信息。这个问题花了我超过48小时。我已按照该链接中的所有说明进行操作,但问题仍然存在。请有人指出我错过了什么。

错误日志:

  

错误:错误:无法加载默认凭据。浏览到   https://developers.google.com/accounts/docs/application-default-credentials   欲获得更多信息。       at /user_code/node_modules/@google-cloud/translate/node_modules/google-auth-library/lib/auth/googleauth.js:316:21       at /user_code/node_modules/@google-cloud/translate/node_modules/google-auth-library/lib/auth/googleauth.js:346:7       在Request._callback(/user_code/node_modules/@google-cloud/translate/node_modules/google-auth-library/lib/transporters.js:70:30)       at self.callback(/user_code/node_modules/@google-cloud/translate/node_modules/request/request.js:186:22)       在emitOne(events.js:96:13)       在Request.emit(events.js:188:7)       在Request.onRequestError(/user_code/node_modules/@google-cloud/translate/node_modules/request/request.js:878:8)       在emitOne(events.js:96:13)       在ClientRequest.emit(events.js:188:7)       在Socket.socketErrorListener(_http_client.js:309:9)

 function translateText(Text, Target) {
  // [START translate_translate_text]
  // Imports the Google Cloud client library
  const Translate = require('@google-cloud/translate');

// Your Google Cloud Platform project ID
const projectId = 'xxxxxxxxxx';

// Instantiates a client
const translate = new Translate({
  projectId: projectId,
});


// Translates some text into Russian
translate
  .translate(Text, Target)
  .then(results => {
    const translation = results[0];

    console.log(`Text: ${text}`);
    console.log(`Translation: ${translation}`);
    return translation;
  })
  .catch(err => {
    console.error('ERROR:', err);
  });
}

0 个答案:

没有答案