[英]How do I efficiently load someone's steam inventory and price of their every item on my website?
I am running Node.js server and I want to load user's inventory so they can see their item and values of each item using JavaScript.我正在运行 Node.js 服务器,我想加载用户的库存,以便他们可以使用 JavaScript 查看他们的项目和每个项目的值。 I have tried to approach this problem by making multiple XHR request.
我试图通过发出多个 XHR 请求来解决这个问题。 First request requests user's items and the others are for each item to get their value.
第一个请求请求用户的项目,其他请求是为每个项目获取它们的值。 Of course, having this much XMLHttpRequests causes problems, and I am not able to get all of the items displayed if any.
当然,拥有这么多 XMLHttpRequests 会导致问题,而且我无法显示所有项目(如果有的话)。 How should I get this working?
我应该如何让它工作? Should I store player's inventory instead of loading it every time?
我应该存储玩家的物品栏而不是每次都加载它吗? But what if the contents change?
但是,如果内容发生变化怎么办? Also, I need to find a way for getting price of each item more efficiently.
此外,我需要找到一种更有效地获取每件商品价格的方法。 Should I store prices somewhere in my database?
我应该将价格存储在数据库中的某个位置吗?
I'm using following APIs我正在使用以下 API
Get inventory contents: https://steamcommunity.com/profiles/{STEAMID}/inventory/json/730/2 Get price of item: https://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name={ITEM'S MARKET_HASH_NAME}获取库存内容: https ://steamcommunity.com/profiles/{STEAMID}/inventory/json/730/2 获取商品价格: https://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name={项目的MARKET_HASH_NAME}
The market/priceoverview endpoint has a very low rate limit and you probably don't want to call it every time you need the price of an item. market/priceoverview 端点的速率限制非常低,您可能不希望每次需要商品价格时都调用它。 Storing the result in a database is definitely a good start but depending on how many items you want to track that wont be enough.
将结果存储在数据库中绝对是一个好的开始,但取决于您要跟踪的项目数量,这还不够。 A good workaround would be to use a third party API.
一个好的解决方法是使用第三方 API。 Either use prices from a different marketplace, which provides an API to get the prices for all your item's in a single call or an API which provides cached data from Steam.
使用来自不同市场的价格,它提供了一个 API 来在一次调用中获取所有项目的价格,或者使用一个 API,它提供来自 Steam 的缓存数据。 CSGO Trader provides an API which combines prices over the most common marketplaces (including the Steam Market).
CSGO Trader提供了一个 API,它结合了最常见的市场(包括 Steam 市场)的价格。
https://prices.csgotrader.app/latest/prices_v6.json
hosts a list for all CS:GO Items which is updated every 8 hours. https://prices.csgotrader.app/latest/prices_v6.json
托管所有 CS:GO 物品的列表,该列表每 8 小时更新一次。 For Market Data of other app's you depend on Services like SteamApis .对于其他应用程序的市场数据,您依赖于SteamApis等服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.