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를 얻기에 경험이 있었나요? 내가 뭘 놓치고 있니?
무엇이'err'의 내용입니까? – dan
콘솔에서 잘린 훌륭한 피사체/배열. 몇 분만 기다려주세요. 나는 그것을 추출하려고 노력할 것입니다. – Satki
[docs] (https://nodejs.org/dist/v4.7.0/docs/api/https.html#https_https_request_options_callback)에 따르면 'https.request'의 콜백에있는 첫 번째 매개 변수는 오류가 아니라 데이터입니다. 'err'에있는 객체가 API 응답입니까? – dan