imgur API(httpモジュールでも試されました)で動作するようにnodeJS https.requestまたはhttps.getを取得するのに苦労します。 https.requestのコードは次のとおりです。nodeJSパラメータでimgur APIにアクセスすると、AJAXでは動作しますが、nodeJSでは動作しません。
var https = require('https')
var imgurAPIOptions = {
hostname : 'api.imgur.com',
path: '/3/gallery/search/time/1/?q=cat',
headers: {'Authorization': 'Client-ID xxxxxxxxxxxx'},
json: true,
method: 'GET'
};
https.request(imgurAPIOptions,function(err,imgurResponse){
if (err) {console.log('ERROR IN IMGUR API ACCESS')
} else {
console.log('ACCESSED IMGUR API');
}
});
エラーメッセージconsole.logが返されます。 jQueryのAJAXを使用して同等のクライアント側の要求のための(作業)のコードはここ
です:
$(document).ready(function(){
$.ajax({
headers: {
"Authorization": 'Client-ID xxxxxxxxxxxx'
},
url: 'https://api.imgur.com/3/gallery/search/time/1/?q=cat',
success:function(data){
console.log(data)
}
})
});
ここで誰が働いimgurのAPIを得ることにどんな経験がありましたか?私は何が欠けていますか?
「エラー」の内容は何ですか? – dan
コンソール上で切り取られた素晴らしいオブジェクト/配列。私に数分を与えると、私は試してそれを抽出します。 – Satki
[docs](https://nodejs.org/dist/v4.7.0/docs/api/https.html#https_https_request_options_callback)によると、 'https.request'のコールバックの最初のパラメータはエラーではなくデータです。 'err'のオブジェクトはAPIレスポンスですか? – dan