duanlongling5308 2016-10-09 22:45 采纳率: 0%
浏览 99

在PHP中使用Steam Web API获取多个贴纸(CSGO)

So i have been having troubles with seeing if a user has more than one of the same sticker in their inventory using the Steam Web API.

http://steamcommunity.com/profiles/76561198188713228/inventory/json/730/2

My current code works perfectly fine when displaying any other item that has an amount greater than one, but when it comes to displaying a sticker it will only display one on the site.

Here is my code:

            $Steam_inv= file_get_contents($urls[2]);
            $Steam_Json = json_decode($Steam_inv, true);

            echo "User is logged in (steamID: $matches[1])
";


            //var_dump($Steam_Json['rgDescriptions']['1989271297_0']['market_name']);
            $TotalItems = 0;

            foreach ($Steam_Json['rgDescriptions'] as $item){
                $TotalItems++;
                $itemBD = json_encode($item);
                $itemAD = json_decode($itemBD, true);

                $result = json_encode($itemAD['market_name']);
                $result = str_replace('"', " ", json_encode($itemAD['market_name']));
                $result = str_replace('Factory New', "FN", $result);
                $result = str_replace('Minimal Wear', "MW", $result);
                $result = str_replace('Field-Tested', "FT", $result);
                $result = str_replace('Well-Worn', "WW", $result);
                $result = str_replace('Battle-Scarred', "BS", $result);
                $result = str_replace('\u2122', " ", $result);
                $result = str_replace('\u2605', " ", $result);                  

                $WepType = json_encode($itemAD['tags'][0]['internal_name']);
                $WepType = str_replace('"', "", $WepType);


                    if($WepType != "CSGO_Type_WeaponCase" && $WepType != "CSGO_Type_Knife")
                    {
                    $colors = json_encode($itemAD['tags'][4]['color']);
                    $colors = str_replace('"', "", $colors);
                    }
                    elseif ($WepType == "CSGO_Type_Knife"){
                        $colors = "FFD700";
                        $result = "★" . $result;
                    }


                $pics = json_encode($itemAD['classid']);
                $pics = str_replace('"', "", $pics);
                echo "<p style='color:#$colors;position:relative;left:50%;'>" . $result . "</p>" . "<img class='Guns' src='https://steamcommunity-a.akamaihd.net/economy/image/class/730/$pics'></img>";
            }
            echo $TotalItems;

Sorry if its sloppy, im really new to PHP.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题