1

so basically Im trying to get steam player inventory in PHP from geting json content but I cannot figure out how to do it, espcially I didn't work with json a lot before. I have a problem with what I should pick in PHP to get what I want from the JSON.

PHP:

    $inventoryJsonUrl = 'http://steamcommunity.com/inventory/'.$steamID.'/730/2?l=english&count=5000';
    $inventoryJsonGet = file_get_contents($inventoryJsonUrl);
    $inventory = json_decode($inventoryJsonGet, TRUE);

    for ($i=0; $i < count($inventory['assets']) ; $i++) { 
        echo $inventory['assets'];
    }

And lets say the $inventoryJsonURL is now http://steamcommunity.com/inventory/76561198260345960/730/2?l=english&count=5000

And I have problem with getting what I want, I mean lets say that in the for loop I want to have name of the item/skin, id of that item and some more things. But I don't know how and what I suppose to pick to get that.

Sorry for bad bad English.

Thanks in advance.

Coder
  • 13
  • 3
  • I think the data you are looking for is in the section `description`, not `assets`. The `classid` and `instanceid` seems to match the one from `assets`, but there are also `name` and `tags` – dbrumann Dec 10 '17 at 21:00
  • If I change it ro $inventory['descriptions']['classid'] I get errors that: Notice: Undefined index: instanceid. That's the problem because I have tried some things instead of assets as I did thought it might be not what I want. – Coder Dec 10 '17 at 21:03

2 Answers2

0

The endpoint contains two lists: assets and descriptions. It's hard to offer some help if you don't really know what you are looking for. I think what you are looking for is descriptions, as there is all the data. See here for the first item: https://www.dropbox.com/s/z736vu6boh9rfi6/steam1.gif?dl=0 Seems as tho that is a shotgut from Counterstrike GO.

Also, this article may help you a bit: Getting someone's Steam inventory

And as a start, I suggest to beautify the content of that json, so you have a better overview of what's in there. I usually use https://codebeautify.org/jsonviewer but there are several other.

andi79h
  • 1,087
  • 1
  • 12
  • 18
  • I will definetly look at that! Thanks also for the json beatifier, I did use but on different site but I preffer this one now/ – Coder Dec 10 '17 at 21:39
0

You can make use of PHP's foreach loop.

$inventories = json_decode($inventoryJsonGet , TRUE);

// you can check the structure of your array by 
// print_r($inventories)
foreach ($inventories['descriptions'] as $key => $description) {
    echo '<pre>';
    echo $description['appid'];
    echo $description['market_name'];
    echo '</pre>';
}
Dexter Bengil
  • 5,995
  • 6
  • 35
  • 54