我试图通过javascript (ReactJS)向Wit.ai提出API请求。“我的浏览器网络”选项卡显示调用失败,消息如下:
“错误”:“错误,请检查令牌/参数”
但是,同样的调用在Wit.ai日志中显示为成功。我已经验证了凭证是正确的,我可以成功地通过终端cUrl呼叫。
这里有个电话:
async action() {
const resp = await fetch('https://api.wit.ai/message?v=20160526&q=hello', {
method: 'GET',
headers: {
'Authorization': "Bearer " + accessToken
},
dataType: 'jsonp',
mode: 'no-cors',
credentials: 'include'
}).then(resp => resp.json()).catch(e => console.log('Boo', e));
}发布于 2016-09-24 14:26:03
因为它是JSONP请求,所以即使请求已正确执行,也会有“意外的输入结束”。我甚至不确定在没有通过应用服务器代理请求的情况下,是否有任何方法使其工作。无论如何,对于这种请求,完全删除headers并将访问令牌作为access_token查询param移动到查询字符串中:
await fetch(`https://api.wit.ai/message?v=20160526&q=hello&access_token=${accessToken}`, {
method: 'GET',
dataType: 'jsonp',
mode: 'no-cors',
credentials: 'include'
}).then(resp => resp.json()).catch(e => console.log('Boo', e));请查看浏览器上的"Network“选项卡,以确保请求已成功解析,即使在执行此catch调用期间已到达fetch块。
https://stackoverflow.com/questions/39628626
复制相似问题