i keep getting error when trying use imgur search api in nodejs:
{"data":{"error":"imgur temporarily on capacity. please try again later."},"success":false,"status":500}
i dont error when accessing api through rest client makes me think i'm doing wrong. when use rest client results expect. how i'm accessing api in node.
var https = require("https"); var options = { protocol:"https:", host:"api.imgur.com", path:"3/gallery/search/top/all/0?q=cats", headers:{"authorization" : "client-id ***********"} } var req = https.request(options, function(response) { var str = ''; response.on('data', function (chunk) { str += chunk; }); response.on('end', function () { console.log(str); }); }); req.end();
your path
in request options
incorrect. prepend /
, voila!
simply change:
path:"3/gallery/search/top/all/0?q=cats",
to
path:"/3/gallery/search/top/all/0?q=cats",
the following worked me!
var https = require("https"); var options = { protocol:"https:", host:"api.imgur.com", path:"/3/gallery/search/top/all/0?q=cats", headers:{"authorization" : "client-id {your_id}"} } var req = https.request(options, function(response) { var str = ''; response.on('data', function (chunk) { str += chunk; }); response.on('end', function () { console.log(json.parse(str)); }); }); req.end();
Comments
Post a Comment