javascript - 上传 Intent 函数 Dialogflow V2
问题描述
我正在尝试开发一个 API 来将意图上传到Dialogflow
V2。我尝试了下面的代码片段,但它不起作用,但是如果尝试与之通信Dialogflow
确实有效(检测意图)并且确实从Dialogflow
for 查询中得到了答复。
允许
我是和管理员 > 服务帐户 > DIALOGFLOW 管理员
错误
错误:7 PERMISSION_DENIED:“projects/dexter-47332/agent”上的 IAM 权限“dialogflow.entityTypes.create”被拒绝。
博客/参考
- Dialogflow 简单的授权方式
- https://github.com/dialogflow/dialogflow-nodejs-client-v2/blob/master/samples/resource.js#L26
- https://www.npmjs.com/package/dialogflow
- https://developers.google.com/apis-explorer/
- https://cloud.google.com/docs/authentication/production
//------- keys.json (test 1)
{
"type": "service_account",
"project_id": "mybot",
"private_key_id": "123456asd",
"private_key": "YOURKEY",
"client_email": "yourID@mybot.iam.gserviceaccount.com",
"client_id": "098091234",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/yourID%40mybot.iam.gserviceaccount.com"
}
//--------------------- ** (test 2) ** ---------
let privateKey = 'key';
let clientEmail = "email";
let config = {
credentials: {
private_key: privateKey,
client_email: clientEmail
}
}
function createEntityTypes(projectId) {
// [START dialogflow_create_entity]
// Imports the Dialogflow library
const dialogflow = require('dialogflow');
// ******** Instantiates clients (Test 1)********
const entityTypesClient = new dialogflow.EntityTypesClient({
'keyFilename': './keys.json'
});
const intentsClient = new dialogflow.IntentsClient({
'keyFilename': './keys.json'
});
// ******** Instantiates clients (Test 2)********
const entityTypesClient = new dialogflow.EntityTypesClient(config);
const intentsClient = new dialogflow.IntentsClient(config);
// The path to the agent the created entity type belongs to.
const agentPath = intentsClient.projectAgentPath(projectId);
const promises = [];
// Create an entity type named "size", with possible values of small, medium
// and large and some synonyms.
const sizeRequest = {
parent: agentPath,
entityType: {
displayName: 'test',
kind: 'KIND_MAP',
autoExpansionMode: 'AUTO_EXPANSION_MODE_UNSPECIFIED',
entities: [{
value: 'small',
synonyms: ['small', 'petit']
},
{
value: 'medium',
synonyms: ['medium']
},
{
value: 'large',
synonyms: ['large', 'big']
},
],
},
};
promises.push(
entityTypesClient
.createEntityType(sizeRequest)
.then(responses => {
console.log('Created size entity type:');
logEntityType(responses[0]);
})
.catch(err => {
console.error('Failed to create size entity type ----->:', err);
})
);
}
createEntityTypes(projectId);
解决方案
我遇到了同样的错误。我通过删除当前服务帐户并创建一个新帐户并为该角色选择“所有者”选项来纠正它。
推荐阅读
- python - Python 和 matplotlib:绘图图例中上标和下标字符的相等垂直间距(使用 Arial)
- nsis - NSIS 安装程序如何跟踪每个用户的安装
- javascript - 如何将 Semver 与针对私有存储库的 NPM 依赖项一起使用?
- google-colaboratory - 使用 R 内核将私有数据导入 Google Colab 笔记本
- groovy - Groovy:无法解析类 org.apache.poi.xssf.usermodel.XSSFSheet
- google-translate - 是否可以自动翻译 Google Data Studio 中的内容?
- c# - 如何同时添加新成员和覆盖抽象成员?
- jooq - JOOQ 示例,例如 zvon.org,用于查询,尤其是连接查询
- python-3.x - 两个熊猫系列之间的匹配ID
- dns - 如何设置DNS,让一个gitlab页面的根域和子域指向同一个地址?