Closed pillowcases closed 7 years ago
Hi
Here is where it throws an error. When you call profile.getStats(options)
do you pass the options variable? If not it selects received season, region and SOLO match.
const selectedStats = this.stats.find((stat) => (
stat.Region === region
&& stat.Season === season
&& stat.Match === match
));
if (!selectedStats) {
throw new StatsNotFound();
}
I tried and works fine:
const {PubgAPI} = require('./');
const fs = require('fs');
const api = new PubgAPI({apikey: process.env.PUBG_APIKEY});
const nickname = 'ninja';
api.getProfileByNickname(nickname)
.then((profile) => {
const data = profile.getStats();
fs.writeFileSync(`./testing-accounts/${nickname}.json`, JSON.stringify(data, null, 2));
});
Output:
{
"region": "na",
"defaultRegion": "na",
"season": "2017-pre3",
"defaultSeason": "2017-pre3",
"match": "solo",
"lastUpdated": "2017-08-22T07:38:38.1980493Z",
"playerName": "Ninja",
"performance": {
"killDeathRatio": 1,
"winRatio": "0",
"timeSurvived": 3300.25,
"roundsPlayed": 6,
"wins": "0",
"winTop10Ratio": "0",
"top10s": "0",
"top10Ratio": "0",
"losses": 6,
"winPoints": 995
},
"skillRating": {
"rating": 1202,
"bestRating": 1228.99,
"bestRank": 546639
},
"perGame": {
"damagePg": 114.23,
"headshotKillsPg": "0",
"healsPg": 0.17,
"killsPg": 1,
"moveDistancePg": 1047.23,
"revivesPg": "0",
"roadKillsPg": "0",
"teamKillsPg": "0",
"timeSurvivedPg": 550.04,
"top10sPg": "0"
},
"combat": {
"kills": 6,
"assists": "0",
"suicides": "0",
"teamKills": "0",
"headshotKills": "0",
"headshotKillRatio": "0",
"vehicleDestroys": "0",
"roadKills": "0",
"dailyKills": 1,
"weeklyKills": 1,
"roundMostKills": 4,
"maxKillStreaks": 1,
"weaponAcquired": "0"
},
"survival": {
"days": 3,
"longestTimeSurvived": 1483.86,
"mostSurvivalTime": 1483.86,
"avgSurvivalTime": 550.04
},
"distance": {
"walkDistance": 6283.4,
"rideDistance": "0",
"moveDistance": 6283.4,
"avgWalkDistance": 1047.23,
"avgRideDistance": "0",
"longestKill": 21.62
},
"support": {
"heals": 1,
"revives": "0",
"boosts": 4,
"damageDealt": 685.38,
"dBNOs": "0"
}
}
Same with the rest of them. Maybe PUBGTracker API was down when you tried.
Anyway, can you post the code where you call the API? Thanks
I'm still getting the same error by trying your code. Error:
{ ProfileNotFound: Error updating stats. Please try again later.
at Promise.resolve.then (/mnt/q/Bots/bot dev/apibot/playerunknowns/node_modules/pubg-api-redis/src/client.js:60:17)
at tryCatcher (/mnt/q/Bots/bot dev/apibot/playerunknowns/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/mnt/q/Bots/bot dev/apibot/playerunknowns/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/mnt/q/Bots/bot dev/apibot/playerunknowns/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/mnt/q/Bots/bot dev/apibot/playerunknowns/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/mnt/q/Bots/bot dev/apibot/playerunknowns/node_modules/bluebird/js/release/promise.js:693:18)
at Async._drainQueue (/mnt/q/Bots/bot dev/apibot/playerunknowns/node_modules/bluebird/js/release/async.js:133:16)
at Async._drainQueues (/mnt/q/Bots/bot dev/apibot/playerunknowns/node_modules/bluebird/js/release/async.js:143:10)
at Immediate.Async.drainQueues (/mnt/q/Bots/bot dev/apibot/playerunknowns/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:672:20)
at tryOnImmediate (timers.js:645:5)
at processImmediate [as _immediateCallback] (timers.js:617:5) name: 'ProfileNotFound' }
My code:
telegram.onText(/^\/stats (.+)/i, async (msg, match) => {
let username = match[1]
let stats = await api.getProfileByNickname(username)
let solo = stats.getStats({
region: REGION.ALL,
season: SEASON.EA2017pre3,
match: MATCH.SOLO
});
The first error was StatsNotFound
and now is ProfileNotFound
.
StatsNotFound
is when you get the correct response but getStats
fails because region
, season
or match
is not correct in data, or there are no data for that options.
ProfileNotFound
is when PUBG Tracker api fails, or playername doesn't exist.
Okay, so I removed region and season from options and just left match, and now the usernames I listed in the beginning of the issue work, except for the username with the dash, and now a new username, shroud. I tried with all options set and none at all, could not get it to work at all. Tried using postman for shroud and that worked fine, so I am really confused now.
Nice, could you tell me the username with dash? I will try and see why it fails.
Thank you.
This works for me:
const {PubgAPI} = require('pubg-api-redis');
const apikey = '';
const username = 'Douyu-728636';
const api = new PubgAPI({apikey});
api.getProfileByNickname(username)
.then((profile) => {
console.log(profile.content);
});
The username with the dash is papa-john.
Got it... By default, match is solo
and this player haven't solo matches. Thats the problem.
This are the available data:
Stats:
[ { Region: 'na',
Season: '2017-pre3',
Match: 'duo',
Stats: [Array] },
{ Region: 'na',
Season: '2017-pre3',
Match: 'squad',
Stats: [Array] },
{ Region: 'agg',
Season: '2017-pre3',
Match: 'duo',
Stats: [Array] },
{ Region: 'agg',
Season: '2017-pre3',
Match: 'squad',
Stats: [Array] } ],
A friend of mines username contains a - in it and we've both tried to get stats for it, and no luck.
Returned this error:
{ StatsNotFound: Stats not found at Profile.getStats (/mnt/q/Bots/bot dev/apibot/playerunknowns/node_modules/pubg-api-redis/src/api/profile-object.js:41:13) at telegram.onText (/mnt/q/Bots/bot dev/apibot/playerunknowns/small.js:72:25) name: 'StatsNotFound' }
Some regular usernames wouldn't work either, such as:
I know for sure that these are real usernames because on pubgtracker.com they work with no problem.
EDIT: I used postman to query the API for the username that didn't work using the wrapper and it all showed up on postman with no issue.