Closed Cansiny0320 closed 1 year ago
sorry, it's not a bug,please remove bug label
how did you get that item id? that is difficult to find.
there is my code
import { AuthClient } from '@valapi/auth'
import { Client as WebClient } from '@valapi/web-client'
import { Region } from '@valapi/lib'
const config = {
region: Region.Default.Asia_Pacific,
throwOnError: true,
}
const authClient = new AuthClient(config)
const login = async () => {
await authClient.login('xxx', 'xxx')
}
const main = async () => {
await login()
const subject = authClient.getSubject()
const json = authClient.toJSON()
const webClient = new WebClient(config)
webClient.fromJSON(json)
const data = await webClient.Store.getStorefront(subject)
console.log(data.data.SkinsPanelLayout.SingleItemOffers[0])
}
main()
here you are, try it first maybe it doesn't work.
const getOffers = await WebClient.Store.getOffers();
async function getOffersOf(ItemsId: string) {
let Store_Display_Name = "";
let Store_Display_Icon = "";
const GetWeaponSkinLevel = await ValorantApiCom.Weapons.getSkinLevels();
for (const _SkinLevel of GetWeaponSkinLevel.data.data) {
if (_SkinLevel.uuid === ItemsId) {
Store_Display_Name = _SkinLevel.displayName;
Store_Display_Icon = _SkinLevel.displayIcon;
break;
}
}
return {
Name: Store_Display_Name,
Icon: Store_Display_Icon
};
}
const AllOffers = (await WebClient.Store.getStorefront("subject")).data.SkinsPanelLayout.SingleItemOffers;
for (const ofItemID in AllOffers) {
const ItemID = AllOffers[ofItemID];
const _Offer = await getOffersOf(ItemID);
}
here you are, try it first maybe it doesn't work.
const getOffers = await WebClient.Store.getOffers(); async function getOffersOf(ItemsId: string) { let Store_Display_Name = ""; let Store_Display_Icon = ""; const GetWeaponSkinLevel = await ValorantApiCom.Weapons.getSkinLevels(); for (const _SkinLevel of GetWeaponSkinLevel.data.data) { if (_SkinLevel.uuid === ItemsId) { Store_Display_Name = _SkinLevel.displayName; Store_Display_Icon = _SkinLevel.displayIcon; break; } } return { Name: Store_Display_Name, Icon: Store_Display_Icon }; } const AllOffers = (await WebClient.Store.getStorefront("subject")).data.SkinsPanelLayout.SingleItemOffers; for (const ofItemID in AllOffers) { const ItemID = AllOffers[ofItemID]; const _Offer = await getOffersOf(ItemID); }
it's not work, this request https://pd.ap.a.pvp.net/store/v2/storefront/subject 400 status
maybe it need auth?
yeah
but there is not ApiClient.fromJSON
, any way else?
there is my code now
import { AuthClient } from '@valapi/auth'
import { Client as WebClient } from '@valapi/web-client'
import { Client as ValorantApi } from '@valapi/valorant-api.com'
import { Region } from '@valapi/lib'
const config = {
region: Region.Default.Asia_Pacific,
throwOnError: true,
}
const authClient = new AuthClient(config)
const login = async () => {
await authClient.login('xxx', 'xxx')
}
const main = async () => {
await login()
const subject = authClient.getSubject()
const json = authClient.toJSON()
const webClient = new WebClient(config)
const ApiClient = new ValorantApi({
language: 'zh-CN',
})
webClient.fromJSON(json)
// ApiClient.fromJSON(json)
const data = await webClient.Store.getStorefront(subject)
const getOffers = await webClient.Store.getOffers()
async function getOffersOf(ItemsId: string) {
let Store_Display_Name = ''
let Store_Display_Icon = ''
const GetWeaponSkinLevel = await ApiClient.Weapons.getSkinLevels()
for (const _SkinLevel of GetWeaponSkinLevel.data.data!) {
if (_SkinLevel.uuid === ItemsId) {
Store_Display_Name = _SkinLevel.displayName as string
Store_Display_Icon = _SkinLevel.displayIcon
break
}
}
return {
Name: Store_Display_Name,
Icon: Store_Display_Icon,
}
}
const AllOffers = (await webClient.Store.getStorefront('subject')).data.SkinsPanelLayout
.SingleItemOffers
for (const ofItemID in AllOffers) {
const ItemID = AllOffers[ofItemID]
const _Offer = await getOffersOf(ItemID)
console.log(_Offer)
}
}
main()
yes like that, put my code after your code
@KTNG-3 like this? but it still not working now
import { AuthClient } from "@valapi/auth";
import { Client as WebClient } from "@valapi/web-client";
import { Client as ValorantApi } from "@valapi/valorant-api.com";
import { Region } from "@valapi/lib";
const config = {
region: Region.Default.Asia_Pacific,
throwOnError: true
};
const authClient = new AuthClient(config);
const login = async () => {
await authClient.login("Username", "Password");
};
const main = async () => {
await login();
const subject = authClient.getSubject();
const webClient = WebClient.fromJSON(authClient.toJSON());
const ApiClient = new ValorantApi({
language: "zh-CN"
});
const data = await webClient.Store.getStorefront(subject);
// const getOffers = await webClient.Store.getOffers();
async function getOffersOf(ItemsId: string) {
let Store_Display_Name = "";
let Store_Display_Icon = "";
const GetWeaponSkinLevel = await ApiClient.Weapons.getSkinLevels();
if (GetWeaponSkinLevel.data.data) {
for (const _SkinLevel of GetWeaponSkinLevel.data.data) {
if (_SkinLevel.uuid === ItemsId) {
Store_Display_Name = _SkinLevel.displayName as string;
Store_Display_Icon = _SkinLevel.displayIcon;
break;
}
}
}
return {
Name: Store_Display_Name,
Icon: Store_Display_Icon
};
}
const AllOffers = data.data.SkinsPanelLayout
.SingleItemOffers;
for (const ofItemID in AllOffers) {
const ItemID = AllOffers[ofItemID];
const _Offer = await getOffersOf(ItemID);
console.log(_Offer);
}
};
main();
is it work?
The code works fine, but the information is not the same as my store information
hmm, its seem a problem
I can't tell whether I got the wrong id or the id is wrongly mapped to the displayname
there is my log
89b68205-4fe5-2434-a731-e5a734bd4a7a Undercity Bulldog
5f059d7e-413c-445c-e36f-9a9791fba5b0 Origin Crescent Blade
33d3c906-4305-19cf-8770-1eb5207482cc Rush Judge
1b94d997-4db6-014f-4cb8-c1b4df7d7ebc Smite Judge
so you need "displayname" in your language or the item is wrong
i find it
const webClient = new WebClient(config)
webClient.fromJSON(authClient.toJSON())
This needs to be written in order to correctly set the region in config
const webClient = WebClient.fromJSON(authClient.toJSON());
Writing config like this doesn't work
it is ok now, thx
i have got item id '167481de-4732-b44a-06ad-938625015abe' ,so how can i get this item name?