【问题标题】:Steam item history through API (PHP)通过 API (PHP) 的 Steam 项目历史记录
【发布时间】:2016-05-14 18:03:14
【问题描述】:

我对各个方面的编程都比较陌生,所以在提出愚蠢的问题时请多多包涵。我想通过 Steam 的市场 API 获取所选项目的 Steam 价格历史记录,当我登录 Steam 时,可以通过我的浏览器轻松访问该 API。事情是,我想通过一个服务器来做这件事,这给我带来了以下错误:

警告:file_get_contents(http://steamcommunity.com/market/pricehistory/?currency=1&appid=440&market_hash_name=Specialized%20Killstreak%20Brass%20Beast):打开流失败:HTTP 请求失败!第 16 行 PATH 中的 HTTP/1.0 400 错误请求

基本上,我的问题和这个人的一样:How to retrieve steam market price history?,但他的答案是针对 Python 的,而我对 Python 语言真的一无所知。 如果想在 PHP 中执行此操作,或者如果在 PHP 中不可能,我可以使用 JavaScript。

我不是要我可以复制粘贴的代码,我会很高兴有任何开始。

我要开始工作的代码:

// $page is the URL above
$json = json_decode(file_get_contents($page), true);
if($json["success"] == true OR !empty($json))
{
    $results = $json["prices"];
    foreach ($results as $result)
    {
        echo $result . "<br>";
    }

【问题讨论】:

    标签: php steam steam-web-api


    【解决方案1】:

    您链接到的答案设置了steamLogin cookie 以启用对 Steam API 的访问。如果您从浏览器的 cookie 中获取它,则可以将其添加到您的 file_get_contents 请求中,如下所示:

    // Create a stream
    $opts = array(
      'http'=>array(
        'method'=>"GET",
        'header'=> "Cookie: steamLogin=76561198058933558%7C%7C2553658936E891AAD\r\n"
      )
    );
    
    $context = stream_context_create($opts);
    
    // Call the API using the HTTP headers set above
    $file = file_get_contents('http://steamcommunity.com/market/pricehistory/?currency=1&appid=440&market_hash_name=Specialized%20Killstreak%20Brass%20Beast', false, $context);
    

    (reference question)

    【讨论】:

    • 感谢您的回答。虽然我已经按照你的建议做了,但我仍然得到和以前一样的错误,它似乎不起作用。
    • 对于 steamLogin,在 Chrome 中,设置 > 高级 > 内容设置 > cookie > 查看所有 cookie 和站点数据 > 找到 steamcommunity.com > 找到“steamLoginSecure” > 复制“内容”字符串
    猜你喜欢
    • 2021-01-26
    • 2021-04-23
    • 1970-01-01
    • 2020-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-11
    • 2015-10-08
    相关资源
    最近更新 更多