const unirest = require('unirest');
const igdb = require('igdb-api-node').default;
const client = igdb('API 토큰');
var id_list = [];
const log = res => {
console.log(res.url, JSON.stringify(res.body, null, 2));
};
const parse = res => {
for(let i = 0; i < res.body[0]["games"].length; i++) {
id_list[i] = res.body[0]["games"][i];
console.log(id_list[i]);
}
};
function toArray(res) {
for(let i = 0; i < res.body[0]["games"].length; i++) {
id_list[i] = res.body[0]["games"][i];
console.log(id_list[i]);
}
}
client.platforms({
limit: 1,
search: 'Nintendo Switch',
offset: 0,
fields: '*'
}, [
'games',
]).then(toArray);
=======================================================
toArray나 parse나 같은 결과가 나오는데요.
'res'라는 오브젝트가 글로벌 네임스페이스에 있어서 그런건가요?
근데 client.platforma() 에서 .then(console.log(res.body)) 하면 undefined라고 떠요...
res 라는 객체가 어디서 나오는건지 모르겠어요.
client.platforms().then(toArray);
여기서 콜백으로 toArray 함수가 호출되는건가요?
그렇다면 그때 함수인자가 리소스가 되게 api에서 그렇게 디자인되있다는건가..
댓글 0