harsh Posted January 15, 2022 Report Posted January 15, 2022 why vac_friends list is empty when I print at last ? function checkVacID(){ friend_list = friends; vac_friends = [] friend_list.forEach(function(key, index){ axios.get(`https://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key=&steamids=${key}`) .then(function (response) { vac_response = response.data; if(vac_response.players[0]['VACBanned'] == true){ vac_friends.push(vac_response.players[0]) console.log(vac_friends) } }) .catch(function (error) { console.log(error); }) }); console.log(vac_friends) } Quote
Dr. McKay Posted January 15, 2022 Report Posted January 15, 2022 Because you're mixing up async and sync. forEach returns before your requests complete. Also, rather than looping through the friend list, you should split it into chunks of 100 and make one request per chunk, to avoid getting rate limited by the API. Quote
harsh Posted January 24, 2022 Author Report Posted January 24, 2022 On 1/16/2022 at 4:05 AM, Dr. McKay said: Because you're mixing up async and sync. forEach returns before your requests complete. Also, rather than looping through the friend list, you should split it into chunks of 100 and make one request per chunk, to avoid getting rate limited by the API. can you give an example of 100 steamids passing in api like i have 256 friends Quote
Dr. McKay Posted February 2, 2022 Report Posted February 2, 2022 let friendsList = [array of steamids]; let chunks = []; for (let i = 0; i < friendsList.length; i += 100) { chunks.push(friendsList.slice(i, i + 100)); } let chunkResults = await Promise.all(chunks.map(ck => new Promise((resolve, reject) => { try { let result = await axios.get(`https://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key=&steamids=${ck.join(',')}`); if (result && result.data && result.data.players) { return resolve(result.data.players); } reject(new Error('Malformed API response')); } catch (ex) { reject(ex); } }))); let vacFriends = []; chunkResults.forEach((chunkPlayers) => { chunkPlayers.filter(player => player.VACBanned).forEach((bannedPlayer) => { vacFriends.push(bannedPlayer); }); }); Untested and might have bugs SENPAY98K 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.