无法打开流:HTTP请求失败! HTTP / 1.1 401未经授权

时间:2014-01-01 03:00:40

标签: php stream steam

为我的网站设置我的自动捐赠系统我已经完成所有工作,除了在最后一页我得到这个错误。这是通过Steam的Garrys Mod服务器。

错误:警告:file_get_contents(http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=xxxxxxxxxxxxxxxxxxx&steamids=xxxxxxxxxxxxx)[function.file-get-contents]:无法打开流:HTTP请求失败! HTTP / 1.1 401未经授权在/usr/www/angelgaming/public/multiple-rank/inc/page.verify.php上线

Verify.php代码:

<?
    include('apikey.php');
    function toid($friendid) {
    if (substr($friendid,-1)%2==0) $server=0; else $server=1;
    $auth=bcsub($friendid,'76561197960265728');
    $auth=bcsub($auth,$server);
    $auth=bcdiv($auth,2);
    return "STEAM_0:".$server.':'.$auth;
    }
    $string = file_get_contents('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' . $API_KEY . 'steamids=' . $_COOKIE['communityid']);
    $json_a = json_decode($string,true);
    $steamname = $json_a['response']['players'][0]['personaname'];
    $avatar64 = $json_a['response']['players'][0]['avatarfull']; 

?>  
<h4>Verify the information below before you proceed</h4>
<div id="verify">
    <p><b><? echo $steamname; ?></b></p>
    <p><img id="avatar" src="<? echo $avatar64; ?>" style="border-radius: 8px;" /></p>
    <p><h6>Donation Amount: $<? echo RankPrice($_POST["rank"]) . CURRENCY;?></h6></p>
    <br />
    <p>
    <form name="_xclick" action="https://www.paypal.com/nz/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="business" value="<? echo PAYPAL_EMAIL; ?>">
    <input type="hidden" name="currency_code" value="<? echo CURRENCY; ?>">
    <input type="hidden" name="item_name" value="<? echo SERVER_NAME; ?> Donation (<? echo $steamname; ?>)">
    <input type="hidden" name="item_number" value="<? echo toid($_COOKIE['communityid']) . '#' . $_POST["rank"]; ?>">
    <input type="hidden" name="amount" value="<? echo RankPrice($_POST["rank"]); ?>">
    <input role="button" class="btn btn-success" value="Donate" type="submit" alt="Donate to Envidious via PayPal">
    <a href="" role="button" class="btn btn-danger">Go Back</a></form>
    </div>

2 个答案:

答案 0 :(得分:1)

如果您转到文档https://developer.valvesoftware.com/wiki/Steam_Web_API#GetPlayerSummaries_.28v0002.29中列出的网址 http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=XXXXXXXXXXXXXXXXXXXXXXX&steamids=76561197960435530

它给出了401,因为它使用了无效密钥(XXXXXXXX),因为你得到了类似的响应,也可能是你发送了无效的api密钥或根本没有密钥?

答案 1 :(得分:0)

这可能是用户身份验证详细信息问题。我遇到了同样的问题,并通过将用户名和密码传递给标头获得了以下解决方案。

https://www.hashbangcode.com/article/using-authentication-and-filegetcontents