首页 > 解决方案 > Dialogflow API HTTP 请求查询代理不起作用

问题描述

最近我在使用nodeJs 服务器上的Dialogflow API时遇到了一些问题……所以我有一个聊天机器人 GUI,可以将 HTTP 请求发送到 dialogflow 代理(使用 dialogflow API v1),而这个基于用户查询应该发送响应。但是现在,IT 发送了一个错误401 未授权,知道从那以后没有任何代码被更新!我已经放置了调用 dialogflow API 的函数并添加了一些 console.log() 进行调试。该错误位于函数 textRequest 内。

import { ApiAiClient } from 'api-ai-javascript'


const client = new ApiAiClient({accessToken: MY_ACCESS_TOKEN});

methods: {
        dialogflowRequest(queryText){
            document.querySelector('.submit-input').style.opacity = '0.5';
            console.log("==> dialogflow request");
            client.textRequest(queryText).then((response) => {
                console.log("==> client request");
                if(response.result.action == "input.unknown" && this.config.app.googleIt == true){
                    response.result.fulfillment.messages[0].unknown = true
                    response.result.fulfillment.messages[0].text = response.result.resolvedQuery
                } 

                document.querySelector('.submit-input').style.opacity = '1';

                //this.speak(response);
                this.handle(response);
                // VueJS will update the HTML automatically
                this.answers.push(response);

                //reset query and speech
                this.query = '';
                this.speech = config.locale.strings.voiceTitle;
            }).catch((error) => {console.log("unable to log into dialogflow!!!");console.log(error);})
        }

POST https://api.api.ai/v1/query?v=20150910 401(未经授权)

==> 经过一番检查

{"status":{"code":401,"errorType":"unauthorized","errorDetails":"缺少身份验证参数"}}

标签: node.jsapigoogle-cloud-platformdialogflow-es

解决方案


推荐阅读