Skip to content

Commit b911559

Browse files
authored
Update user-trophy-list.md
1. Fetch all data when the total amount exceeds the limit (100 titles per call for now). 2. Add a hint for downloading data for the user's own account instead of "xelnia" in the example.
1 parent 0fc39d0 commit b911559

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

website/docs/examples/user-trophy-list.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ async function main() {
3232
const accessCode = await exchangeNpssoForAccessCode(process.env["NPSSO"]);
3333
const authorization = await exchangeAccessCodeForAuthTokens(accessCode);
3434

35-
// 2. Get the user's `accountId` from the username.
35+
// 2. Get the user's `accountId` from the username 'xelnia'.
36+
// If you set `targetAccountId` to "me", it would download data for your own account.
3637
const allAccountsSearchResults = await makeUniversalSearch(
3738
authorization,
3839
"xelnia",
@@ -44,10 +45,23 @@ async function main() {
4445
.accountId;
4546

4647
// 3. Get the user's list of titles (games).
47-
const { trophyTitles } = await getUserTitles(authorization, targetAccountId);
48-
48+
// Ensure all data is fetched when the totalItemCount exceeds the limit.
49+
const allTitles: TrophyTitle[] = [];
50+
let offset = 0;
51+
while (true) {
52+
const { totalItemCount, trophyTitles } = await getUserTitles( authorization, targetAccountId, { offset });
53+
if (!trophyTitles || trophyTitles.length === 0) {
54+
break;
55+
}
56+
allTitles.push(...trophyTitles);
57+
if (allTitles.length >= totalItemCount) {
58+
break;
59+
}
60+
offset += trophyTitles.length;
61+
}
62+
4963
const games: any[] = [];
50-
for (const title of trophyTitles) {
64+
for (const title of allTitles) {
5165
// 4. Get the list of trophies for each of the user's titles.
5266
const { trophies: titleTrophies } = await getTitleTrophies(
5367
authorization,

0 commit comments

Comments
 (0)