Node.js 难以从dialogflow api v1获得授权。获取错误“请求失败,状态代码401”

Node.js 难以从dialogflow api v1获得授权。获取错误“请求失败,状态代码401”,node.js,axios,dialogflow-es,Node.js,Axios,Dialogflow Es,我正在使用axios将我的机器人连接到dialog flow API v1。它返回一个401错误:“未经授权?” 我已经准备好将标题和数据类型设置为application/json var axios =require('axios'); var URL ='https://api.dialogflow.com/v1/'; let config = { headers: { "Authorization": "Bearer " + '4c52dfb9db61xxxxxx

我正在使用axios将我的机器人连接到dialog flow API v1。它返回一个401错误:“未经授权?”

我已经准备好将标题和数据类型设置为application/json

var axios =require('axios');
var URL ='https://api.dialogflow.com/v1/';

let config = {
    headers: {
        "Authorization": "Bearer " + '4c52dfb9db61xxxxxxxxxxxxx',
        "Content-Type": "application/json"

    }
  }
var bodyParameters = {
    "queryInput": { "text":
     { } 
    },
    "query": "hi hello",
    "languageCode": "en",
    "sessionId": "12345",
    "timezone": "xxxxx"
};


axios.get(URL,bodyParameters, config)
.then(function(res){
    console.log(res.data);

}).catch(function(error){
    console.log(error);

});

授权中有错误吗?

搜索后,我发现使用节点获取进行API请求非常容易

fetch(URL+"query?v=20150910", {
    body: JSON.stringify({query: "new york city", lang: "en", sessionId: "12345"}),
    headers: {
        'content-type': 'application/json',
        "Authorization": "Bearer " + accessToken,
    },
    method: 'POST',
})
    .then(response => response.json())
    .then(data => {
        console.log(data.result.fulfillment.speech);
        return data.result.fulfillment.speech;
    })
    .catch(error => console.error(error))

看看这个。这可能会对你有所帮助谢谢我终于用节点抓取完成了**对于其他感兴趣的人,这里有我的代码**`fetchURL+query?v=20150910,{body:JSON.stringify{query:new york city,lang:en,sessionId:12345},标题:{'content type':'application/JSON',Authorization:Bearer+accessToken,},方法:'POST',}。thenresponse=>response.JSON.thendata=>{console.logdata.result.fulfillment.speech;return data.result.fulfillment.speech;}.catcherror=>console.errorerror`