douwen3083 2015-01-24 16:06
浏览 65

Steam API - 将ID替换为Schema

I find solution for getting id's from API to my website.

But, I still don't know how to replace this: (from http://api.steampowered.com/IEconItems_440/GetPlayerItems/v0001/?key=APIKEY&steamid=76561198108107219&format=json)

"id": 1960542190,
"defindex": 744,

With this: (from http://api.steampowered.com/IEconItems_440/GetSchema/v0001/?key=APIKEY)

"name": "Pyrovision Goggles",
"defindex": 744,

I'm using this:

     $url = "http://api.steampowered.com/IEconItems_440/GetPlayerItems/v0001/?key=" . $api_key . "&steamid=" . $idc . "&format=json";
     $json_object= file_get_contents($url);
     $json_decoded = json_decode($json_object);

      foreach ($json_decoded->result->items as $item)
      {
          $items[$item->id]['id'] = $item->id;
          $items[$item->id]['original_id'] = $item->original_id;
          $items[$item->id]['defindex'] = $item->defindex;
          $items[$item->id]['level'] = $item->level;
          $items[$item->id]['quality'] = $item->quality;


          echo $item->defindex; echo "<br>";
      }
  • 写回答

1条回答 默认 最新

  • duanbo6871 2015-01-24 18:55
    关注

    You have the player's inventory, now you need to pull the Item Schema.

     $url = "http://api.steampowered.com/IEconItems_440/GetSchema/v0001/?key=" $APIKEY;
     $json_object= file_get_contents($url);
     $schema_json_decoded = json_decode($json_object);
     $items_schema = $schema_json_decoded->result->items;   
    

    The schema items are now in the $items variable. In your foreach loop, we need to compare the defindex of the player's item with the defindexes in the schema:

    foreach ($json_decoded->result->items as $item)
      {
          ...
          $items[$item->id]['defindex'] = $item->defindex;
          ...
    
          foreach ($items_schema as $item)
          {
              if ($items[$item->id]['defindex'] == $item->defindex)
              {
                  $items[$item->id]['name'] = $item->item_name;
              }
          }
      }
    

    Your item name is now stored in $items[$item->id]['name'].

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable