【发布时间】:2017-11-28 04:09:16
【问题描述】:
我正在尝试从 imgur api 获得响应,但我无法获得任何东西。我不断收到 401 未授权错误。我也尝试过使用".../gallery/authorization?client_id=###########/search="+req.body.search,但这也不起作用。我不太了解文档。谁能告诉我我做错了什么?哦,顺便说一句,这是用 express/node.js 编写的。
router.post('/getimages', function(req,res,next){
console.log('successfully got to /getimages backend :P');
console.log('the value of the search query is ', req.body.search);
var url = 'https://api.imgur.com/3/gallery/search?q='+req.body.search;
axios.get(url)
.then(function (response) {
console.log('YATA from axios to imgur');
console.log(response);
res.json({'YATA':'YATA from getimages'});
})
.catch(function (error) {
console.log('Fail from axios request to imgur');
console.log(error);
res.json({'OHNOES':'NOOOOYATA from getimages'});
});
})
【问题讨论】:
标签: node.js express xmlhttprequest router axios