Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions website/docs/examples/user-trophy-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ async function main() {
const accessCode = await exchangeNpssoForAccessCode(process.env["NPSSO"]);
const authorization = await exchangeAccessCodeForAuthTokens(accessCode);

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

// 3. Get the user's list of titles (games).
const { trophyTitles } = await getUserTitles(authorization, targetAccountId);

// Ensure all data is fetched when the totalItemCount exceeds the limit.
const allTitles: TrophyTitle[] = [];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also needs to be added to the example import block.

let offset = 0;
while (true) {
const { totalItemCount, trophyTitles } = await getUserTitles( authorization, targetAccountId, { offset });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be more readable:

Suggested change
const { totalItemCount, trophyTitles } = await getUserTitles( authorization, targetAccountId, { offset });
const { totalItemCount, trophyTitles } = await getUserTitles(
authorization,
targetAccountId,
{ offset }
);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, sorry for the late reply! I was caught up with a few other projects in March. Just wanted to check on the merging process for this repo—should I go ahead and update the commit, or were you planning to make the updates on your end?

if (!trophyTitles || trophyTitles.length === 0) {
break;
}
allTitles.push(...trophyTitles);
if (allTitles.length >= totalItemCount) {
break;
}
offset += trophyTitles.length;
}

const games: any[] = [];
for (const title of trophyTitles) {
for (const title of allTitles) {
// 4. Get the list of trophies for each of the user's titles.
const { trophies: titleTrophies } = await getTitleTrophies(
authorization,
Expand Down