Using:
const fs = require('fs');
const path = require('path');
const got = require('got');
var users = {};
let page = 0;
fetchPage = function(c) {
got({
url: 'https://api.twitch.tv/helix/moderation/banned',
searchParams: {
broadcaster_id: 'A BIG STREAMER',
after: c,
first: 100
},
headers: {
authorization: 'Bearer REDACTED'
},
responseType: 'json'
})
.then(resp => {
page++;
for (var x=0;x<resp.body.data.length;x++) {
users[resp.body.data[x].user_id] = 1;
}
console.log('Page',page,'has',resp.body.data.length,'users',Object.keys(users).length);
fs.appendFileSync(path.join(
__dirname,
'pages',
page + '.json'
), JSON.stringify(resp.body,null,4));
if (resp.body.pagination && resp.body.pagination.cursor) {
fetchPage(resp.body.pagination.cursor);
}
})
.catch(err => {
console.log(err);
});
}
fetchPage('');
I got the first 10 pages and the 11th crashed
Page 1 has 100 users 100
Page 2 has 100 users 200
Page 3 has 100 users 200
Page 4 has 100 users 200
Page 5 has 100 users 200
Page 6 has 100 users 200
Page 7 has 100 users 200
Page 8 has 100 users 200
Page 9 has 100 users 200
Page 10 has 100 users 200
{ HTTPError: Response code 500 (Internal Server Error)
at EventEmitter.emitter.on (/REDACTED/misc/node_modules/got/dist/source/as-promise.js:109:31)
at process._tickCallback (internal/process/next_tick.js:68:7) code: undefined, name: 'HTTPError' }
But every page 2 thru 10 were the same.
I don’t use this API to go fetch all the users that are banned, which is why I’ve not noticed this. I use the 1 2 1 look up for specific users and thats working fine/as expected.
For what purpose are you after the whole list for out of interest?
Looks correct?
