2016-08-25 46 views
0

好的,我需要使用蒸汽API獲取csgo庫存。我用這個網址使用蒸汽API獲得CSGO庫存

https://api.steampowered.com/IEconItems_730/GetPlayerItems/v1key= $ API_KEY & steamids = $ steamid

我用這個網址訪問所有CSGO項目。

https://api.steampowered.com/IEconItems_730/GetSchema/v2

問題1,是我無法理解在第一網址返回值。沒有項目名稱,圖像和...。 這是它如何返回

  "id": 547938992, 
      "original_id": 547938992, 
      "defindex": 13, 
      "level": 1, 
      "quality": 4, 
      "inventory": 53, 
      "quantity": 1, 
      "rarity": 1, 
      "attributes": 

問題2,當的是使用第二個URL來獲取所有CSGO皮膚。它只是返回香草皮。我怎麼能得到像其他網站的完整皮膚:opskins,bitkins,csgolounge和....

我知道在Stackoverflow中有很多像這樣的問題,但他們都沒有回答我能理解的方式。

我很抱歉我的英文不好。

回答

2

對於我的項目,我用另一個URL蒸汽的API,

"http://steamcommunity.com/profiles/*insert steamId*/inventory/json/730/2"

您可以嘗試使用您的steamID並粘貼到瀏覽器中,你會看到響應的樣子。這是你將與之合作的內容。

如果您使用此URL進行請求,您將得到一個包含兩部分的json對象的響應。其中一部分名爲rgInventory(ie. data.rgInventory),其中包含用戶csgo-inventory中每個皮膚的id。第二部分叫做rgDescriptions(ie. data.rgDescriptions),包含每個皮膚的info/name/img url。要將信息添加到用戶在rgInventory中的皮膚中,您需要比較rgInventoryrgDescriptions上的每個項目的classIdclassId是決定它是哪種類型的武器的id,因此classid不是唯一的。

那麼什麼Im做是使用兩個for-loops,並比較了ID,以便我可以添加item_urlmarket_name等。爲rgInventory陣列,然後我我送走的回調。像這樣(JavaScript的):

  var ids = getID(data.rgInventory); 
      var item = getItems(data.rgDescriptions); 

      for (var i = 0; i < ids.length; i++) { 
       for (var k = 0; k < item.length; k++) { 
        if (ids[i].classid == item[k].classid) { 
         ids[i].market_name = item[k].market_name; 
         ids[i].icon_url = item[k].icon_url; 
         ids[i].tradable = item[k].tradable; 
        } 
       } 
      } 

所以,如果這兩個項目的ClassID的是一樣的,我將添加我想將變量「IDS」在這種情況下是rgInventory副本的信息。當for-loops完成後,我發回ids變量作爲我的回調。

隨意提出問題,如果這是令人困惑的抱歉。請記住在瀏覽器中鍵入我與蒸汽配置文件鏈接的網址並查看結果。

希望它有幫助!