How get a response of multiple price items on the market
Asked Answered
C

2

-1

I check the price of each items of my backpack cs:go with this link :

http://steamcommunity.com/market/priceoverview/?country=FR&currency=3&appid=440&market_hash_name=

But for 100 items for exemple, i check 100 links for get the price of all my items.

Is it possible to query steam with many items and steam response only one json with all prices requested?

I want it's a system like that, you send a array with all classid of the items you want know the price to a steam url and steam send you one json with all price of your array. For steam it's not difficult and it's very speedy and for me it's very helpul for the speed of query and easier.

Could answered 3/12, 2014 at 11:40 Comment(4)
You should check their documentation out. Your best bet though would be to make a PHP Forloop and then combine all the json together.Timepleaser
There is nothing in their doc that speaks of the market ... At the moment this is what I did but every loop it opens a new url to get the price. So it makes an incredibly long timeCould
You could use CURL to open up the urls and parse them. You should make sure to disable PHP Execution time limits. For the time taken, that can't really be helped, but perhaps you could make a nice loading bar? :)Timepleaser
I actually use cURL but what i want it's a system like that, you send a array with all classid of the items you want know the price to a steam url and steam send you one json with all price of your array. For steam it's not difficult and it's very speedy and for me it's very helpul for the speed of request and easier.Could
H
0

Is it possible to query steam with many items and steam response only one json with all prices requested?

No, it's not possible to query Steam with many items which result in a single response with all the data, however it's possible to use cURL's multiget to send multiple requests which each hit the Steam API returning multiple response in a single cURL call.

Example of a curl multi exec:

function curl_get_contents($data) {
    $curly = array();
    $mh = curl_multi_init();

    foreach ($data as $urlArray) {
        $curly[$urlArray['name']] = curl_init();
        curl_setopt($curly[$urlArray['name']], CURLOPT_URL, $urlArray['url']);
        curl_setopt($curly[$urlArray['name']], CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curly[$urlArray['name']], CURLOPT_HEADER, false);
        curl_setopt($curly[$urlArray['name']], CURLOPT_RETURNTRANSFER, true);
        curl_multi_add_handle($mh, $curly[$urlArray['name']]);
    }

    $running = null;
    do {
        curl_multi_exec($mh, $running);
    } while ($running > 0);

    foreach ($curly as $id => $c) {
        curl_multi_remove_handle($mh, $c);
    }

    curl_multi_close($mh);
 }

I wrote a function much like this one (removed the additional code because I don't want you to just copy/pasta - learn instead) to take an array of arrays where each inner array contains a name and a URL, and returns an array of data accordingly - for example:

$curlyUrls = array(
        array(
        'name' => 'Item1 Response',
        'url'  => 'http://steamcommunity.com/market/priceoverview/?country=ZA&currency=3&appid=730&market_hash_name=Item1'
        ),
        array(
        'name' => 'Item2 Response',
        'url'  => 'http://steamcommunity.com/market/priceoverview/?country=ZA&currency=3&appid=730&market_hash_name=Item2'
        )
);

$curlyItemResponse = curl_get_contents($curlyUrls);

This method is definitely not recommended for 100+ items. I use this for no more than 10 calls - hitting the Steam API too frequently will likely cause some sort of throttling toward your connection not to mentioned, if this is called too frequently, your 100K daily API threshold will be used up pretty fast.

There are a few workarounds to this, but the best approach I can recommend is storing a list of your known items in a database and creating a cronjob to occasionally update the prices of each item while avoiding mass API calls - that way you have a cached price to each item.

Herpes answered 24/12, 2014 at 19:55 Comment(0)
M
-4

I think

  1. populating the data into the JSON
  2. then passing it to the particular page
  3. Get the posted item in the array
  4. now use loop like: foreach and query each id or something in the database and then again store it in the array
  5. now again use loop, if done well step 4 will be the last, to display the related pricing
Massasoit answered 9/12, 2014 at 10:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.