Jump to content

Steam Web API coding help.


TheNoobieCoder

Recommended Posts

Hello.  I am trying to use steam web API to access my steam inventory and report it to my website page.  This is part of what I am originally returned.

{
    "result": {
        "status": 1,
        "num_backpack_slots": 150,
        "items": [
            {
                "id": 1828738510,
                "original_id": 1828738510,
                "defindex": 166,
                "level": 5,
                "quality": 6,
                "inventory": 2147483649,
                "quantity": 1,
                "origin": 0,
                "flag_cannot_trade": true,
                "attributes": [
                    {
                        "defindex": 143,
                        "value": 1373392596,
                        "float_value": 118276915200.000000
                    },
                    {
                        "defindex": 292,
                        "value": 1115684864,
                        "float_value": 64.000000
                    },
                    {
                        "defindex": 388,
                        "value": 1115684864,
                        "float_value": 64.000000
                    },
                    {
                        "defindex": 153,
                        "value": 1065353216,
                        "float_value": 1.000000
                    }
                ]
                
            },
            {
                "id": 1828947688,
                "original_id": 1176490973,
                "defindex": 5009,
                "level": 1,
                "quality": 6,
                "inventory": 2147483650,
                "quantity": 1,
                "origin": 4
            },
            {
                "id": 1828947700,
                "original_id": 1176491289,
                "defindex": 5009,
                "level": 1,
                "quality": 6,
                "inventory": 2147483651,
                "quantity": 1,
                "origin": 4
            },
            {
                "id": 1828947742,
                "original_id": 1178541917,
                "defindex": 5009,
                "level": 1,
                "quality": 6,
                "inventory": 2147483652,
                "quantity": 1,
                "origin": 4
            },
            {
                "id": 1828947755,
                "original_id": 1178542060,
                "defindex": 5009,
                "level": 1,
                "quality": 6,
                "inventory": 2147483757,
                "quantity": 1,
                "origin": 4
            },

And so on.

 

What I would like to do is loop through this data for all of the defindexes of 5001 and count those up and then print them.  So far this is my code.  Ignore the [insert_php], that is what my WordPress plugin uses to start/end it.

[insert_php]
 
 
$json = file_get_contents($api);
$schema = json_decode($json, true);
$total_metal = 0;
foreach($schema as $item)
{
    if (in_array($item->defindex, $schema));
    {
        if($item->defindex == 5001);
        {
            $total_metal+= 3;
        }
        if($item->defindex == 5002);
        {
            $total_metal+= 9;
        }
    }
}   
print $total_metal;
[/insert_php]
 
So far I am only returned 12 when I should be returned 63.    Any help here would be great.  Thanks.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.