【问题标题】:Steam API load the items jsonSteam API 加载项目 json
【发布时间】:2016-06-27 21:25:58
【问题描述】:

大家好,我开始尝试使用 Steam API 并且我已经完成了登录...但是我在获取物品方面遇到了一个大问题。我找不到解决方案我做错了什么。

$GetClientSteamItemsUrl = " http://steamcommunity.com/profiles/" . $_SESSION['steam_steamid'] . "/inventory/json/730/2";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $GetClientSteamItemsUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 3);
$output = curl_exec($ch);
$ArrayInventory = json_decode($output, true);
foreach($ArrayInventory['rgDescriptions'] as $inventory)
{
    echo $inventory;
}

在那个链接上是我想在我的页面上写下他们的名字的项目。

错误:警告:在 /data/web/virtuals/112855/virtual/www/subdom/ayy/index.php 中为 foreach() 提供的参数无效

有人可以帮我选择代码的特定部分吗?

【问题讨论】:

  • foreach() 的第一个参数必须是一个数组,而不是您正在迭代的数组中的键。
  • 无论如何我都无法获取数据
  • 如果您不需要 API 响应中的所有数据来执行特定任务,请考虑从 $ArrayInventory 中提取您需要的特定数据部分到它自己的数据中。我从未与 Steam api 进行过交互,所以我不知道他们的数据结构来提供解决方案。
  • 你确认$ArrayInventory['rgDescriptions']是一个数组了吗?

标签: php json steam


【解决方案1】:

试试这个

$inventory = file_get_contents("http://steamcommunity.com/profiles/".$_SESSION['steamid']."/inventory/json/730/2");
$myarrayInv = json_decode($inventory, true);  
foreach($myarrayInv['rgDescriptions'] as $item) 
{
echo $item['name']; 

}

如果您想要 icon_url 等,请执行 $item['icon_url'],希望这会有所帮助。

【讨论】:

  • 不,那不是问题。再次阅读代码和错误消息。
猜你喜欢
  • 1970-01-01
  • 2014-07-24
  • 1970-01-01
  • 2022-09-26
  • 2016-11-20
  • 2016-05-27
  • 1970-01-01
  • 2016-05-14
  • 2023-03-27
相关资源
最近更新 更多