node.js - Dialogflow Node SDK 权限失败 (dialogflow.sessions.detectIntent)

标签 node.js permissions dialogflow-es google-iam

我在 Node DialogFlow API 集成方面遇到问题。

尽管我已遵循所有可能的文档,但我没有必要的权限来调用 API。

这是我在 Dialogflow 管理中的代理服务帐户:

DialogFlow Service Account 然后是服务帐户角色:

Service Account Authorizations

“Client de l'API Dialogflow”角色详细信息,我们可以在其中看到“dialogflow.sessions.detectIntent”:

DialogFlow API Authorizations

最后,下载服务帐户对应的 JSON 文件后出现 Node 错误:

Node error

我错过了什么吗?

我尝试生成其他 JSON 文件,创建其他服务帐户,但没有任何效果...

Node脚本很简单,只是从官方教程中粘贴过来的:

const projectId = 'newagent-9e77e '; //https://dialogflow.com/docs/agents#settings
const sessionId = 'quickstart-session-id';
const query = 'bonjour';
const languageCode = 'fr-FR';

// Instantiate a DialogFlow client.
const dialogflow = require('dialogflow');
const sessionClient = new dialogflow.SessionsClient();

// Define session path
const sessionPath = sessionClient.sessionPath(projectId, sessionId);

// The text query request.
const request = {
  session: sessionPath,
  queryInput: {
    text: {
      text: query,
      languageCode: languageCode,
    },
  },
};

// Send request and log result
sessionClient
  .detectIntent(request)
  .then(responses => {
    console.log('Detected intent');
    const result = responses[0].queryResult;
    console.log(`  Query: ${result.queryText}`);
    console.log(`  Response: ${result.fulfillmentText}`);
    if (result.intent) {
      console.log(`  Intent: ${result.intent.displayName}`);
    } else {
      console.log(`  No intent matched.`);
    }
  })
  .catch(err => {
    console.error('ERROR:', err);
  });

谢谢!

最佳答案

问题出在“projectId”常量上的空间上。 我真丢脸。

关于node.js - Dialogflow Node SDK 权限失败 (dialogflow.sessions.detectIntent),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50325963/

相关文章:

node.js - 错误!无效 : strip-ansi@0. 2.2

node.js - 在 multer nodejs 中跟踪文件上传的进度

permissions - 应用程序无法使用 Vagrant 创建可写文件夹

python - 检测 Django 测试中的权限错误

dialogflow-es - 是否可以让我的对话流代理在互联网上搜索未解决问题的答案?

node.js - 如何调用dialogflow v2中的事件:nodejs

javascript - 如何检索类中变量的值

node.js - Sequelize 关联的某些设置不起作用

PHP 用户以外的用户的 PHP exec() 命令函数

google-cloud-platform - Dialogflow 中的多个快速回复