【发布时间】: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']是一个数组了吗?