1

I am trying to make a "echo" prices for different objects I have got in an array that contains weapons:

I have read lots about how to get prices through through Steammarket through Steamapi:
(none of these sources did fit my requirements) Sources:
Get steam item prices
How get a response of multiple price items on the market
Get the price of an item on Steam Community Market with PHP and Regex

I found finally a code snippet that works flawless

FILE marketprices.php

<?php

     $items = array("Exalted Manifold Paradox","Kinetic Gem","Mercurial's Call");
        foreach($items as $item)
        {
            $json = json_decode(file_get_contents("http://steamcommunity.com/market/priceoverview/?appid=570&market_hash_name=".rawurlencode($item)), true);
            if($json["success"] == true OR !empty($json))
            {
                echo $item."'s lowest price is ".$json["lowest_price"]."";
            }
            elseif($json["success"] == false OR empty($json))
            {
                echo "Could not get data for ".$item;
            }
        }

output>

Exalted Manifold Paradox's lowest price is $28.49Kinetic Gem's lowest price is $50.00Mercurial's Call's lowest price is $0.16

Source:http://gamebanana.com/tuts/11942

When I am trying to implent this snippet to my code I get error in my result:

I have created an array that contains different weapons:
<?
    foreach($S_W as $item) // Steam weapon
    {
    echo $item;
    }

?>

output>

AWP | Worm God (Factory New)
FAMAS | Cyanospatter (Field-Tested)
G3SG1 | Green Apple (Factory New)
G3SG1 | Polar Camo (Field-Tested)
Glock-18 | Death Rattle (Field-Tested)
M249 | Gator Mesh (Field-Tested)
MAC-10 | Heat (Field-Tested)

This is good so far..

I get error in the result Here is my code below:

foreach($S_W as $item)
{
    $json = json_decode(file_get_contents("http://steamcommunity.com/market/priceoverview/?appid=570&market_hash_name=".rawurlencode($item)), true);
    if($json["success"] == true OR !empty($json))
    {
        echo $item."'s lowest price is ".$json["lowest_price"]."";
    }
    elseif($json["success"] == false OR empty($json))
    {
        echo "Could not get data for ".$item;
    }
}

I receive following result: enter image description here

I see a part of the error.. in the call in the end of the URL the code adds:&lt;/br&gt;

Could someone help me with a solution?

Thank you in advance

Best regards

Daniel

Community
  • 1
  • 1
XsiSecOfficial
  • 954
  • 8
  • 20
  • Are the snippets of code above from `MarketPrices.php` and do they show the offending lines? – Professor Abronsius Feb 16 '16 at 10:06
  • @DanielElmnas: The decoded value of `</br>` is ``. That means the value has a single line break. Try the PHP's `strip_tags()` first. – CAPS LOCK Feb 16 '16 at 10:56
  • Could you explain more in detail I am a newbie to PHP. Could you provide me with a snippet? Thank you in advance – XsiSecOfficial Feb 16 '16 at 12:02
  • 1
    @DanielElmnas: also, you have a `&` in the URL that you should replace. And delete the answer you posted as it is not an answer. You should update your question instead. – CAPS LOCK Feb 16 '16 at 12:34
  • So the following result of the URL, should look like the example below: http://steamcommunity.com/market/priceoverview/?appid=570/market_hash_name=AWP%20|%20Worm%20God%20(Factory%20New) If I paste that in the browser I still get null thank you in advance – XsiSecOfficial Feb 16 '16 at 12:37
  • 1
    @DanielElmnas: change `570/market_hash_name` to `570&market_hash_name`. It gets you some json. I am not familiar with how steam API works, though. – CAPS LOCK Feb 16 '16 at 12:44
  • I still get null: http://pastebin.com/7e4vVVbf – XsiSecOfficial Feb 16 '16 at 12:47

1 Answers1

-1

Priceoverview 'API' endpoint is rate-limited by Steam, and was even further rate-limited by Valve very recently. You are getting 429 HTTP Status code, which stands for 'Too many requests', you are sending requests to their site way too often.

ncla
  • 803
  • 9
  • 22
  • How do other people solve to create an array from the pricelist? Thank you in advance – XsiSecOfficial Feb 22 '16 at 07:36
  • @DanielElmnas one way would be to send requests under x amount per minute, I believe it may have been something like 20 requests/minute. – ncla Feb 22 '16 at 13:06
  • If I should send x requests per min how should you make it then? Could you help me with an example if it is not to hard. by using the method I am using. Is this the easiest way to make this? Thank you in advance – XsiSecOfficial Feb 22 '16 at 13:28
  • Just noticed that you are sending incorrect appID for the CS:GO items, 570 is for Dota 2, 730 is for CS:GO. – ncla Mar 07 '16 at 18:10