我正在尝试使用Steam API提供的新功能,但我遇到了麻烦,我认为这比一般服务相关的问题更为普遍。
我一直在:
无法打开流:HTTP请求失败! HTTP / 1.0 403禁止
我正在尝试使用以下参数发送带有参数的GET请求:
<?php
$url = "https://api.steampowered.com/ICSGOTournaments_730/GetTournamentItems/v1?key=".$_SESSION['steam_appid']."&event=9&steamid=".$_SESSION['steam_steamid']."&steamidkey=".$_SESSION['userAuthCode'];
$response = file_get_contents($url);
echo($response);
?>
我100%确定参数是否正确我认为这与我的代码相比,而不是Steam本身。
当我尝试使用相同的代码但不同的API调用时:
$url = "https://api.steampowered.com/ICSGOTournaments_730/GetTournamentLayout/v1?key=".$_SESSION['steam_appid']."&event=9";
执行正常并返回数据,因此它与其他两个参数相关。
我想知道构建网址的方式有什么问题吗?
会话文件(第三方):
<?php
if (empty($_SESSION['steam_uptodate']) or empty($_SESSION['steam_personaname'])) {
require 'SteamConfig.php';
$url = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=".$steamauth['apikey']."&steamids=".$_SESSION['steamid']);
$content = json_decode($url, true);
$_SESSION['steam_appid'] = $steamauth['apikey'];
$_SESSION['steam_steamid'] = $content['response']['players'][0]['steamid'];
$_SESSION['steam_communityvisibilitystate'] = $content['response']['players'][0]['communityvisibilitystate'];
$_SESSION['steam_profilestate'] = $content['response']['players'][0]['profilestate'];
$_SESSION['steam_personaname'] = $content['response']['players'][0]['personaname'];
$_SESSION['steam_lastlogoff'] = $content['response']['players'][0]['lastlogoff'];
$_SESSION['steam_profileurl'] = $content['response']['players'][0]['profileurl'];
$_SESSION['steam_avatar'] = $content['response']['players'][0]['avatar'];
$_SESSION['steam_avatarmedium'] = $content['response']['players'][0]['avatarmedium'];
$_SESSION['steam_avatarfull'] = $content['response']['players'][0]['avatarfull'];
$_SESSION['steam_personastate'] = $content['response']['players'][0]['personastate'];
if (isset($content['response']['players'][0]['realname'])) {
$_SESSION['steam_realname'] = $content['response']['players'][0]['realname'];
} else {
$_SESSION['steam_realname'] = "Real name not given";
}
$_SESSION['steam_primaryclanid'] = $content['response']['players'][0]['primaryclanid'];
$_SESSION['steam_timecreated'] = $content['response']['players'][0]['timecreated'];
$_SESSION['steam_uptodate'] = time();
include 'mysql_connection.php';
$userAuth = getAuth();
if($userAuth != false){
$_SESSION['userAuthCode'] = $userAuth;
}
else{
$_SESSION['userAuthCode'] = "Unset";
}
}
$steamprofile['steamid'] = $_SESSION['steam_steamid'];
$steamprofile['communityvisibilitystate'] = $_SESSION['steam_communityvisibilitystate'];
$steamprofile['profilestate'] = $_SESSION['steam_profilestate'];
$steamprofile['personaname'] = $_SESSION['steam_personaname'];
$steamprofile['lastlogoff'] = $_SESSION['steam_lastlogoff'];
$steamprofile['profileurl'] = $_SESSION['steam_profileurl'];
$steamprofile['avatar'] = $_SESSION['steam_avatar'];
$steamprofile['avatarmedium'] = $_SESSION['steam_avatarmedium'];
$steamprofile['avatarfull'] = $_SESSION['steam_avatarfull'];
$steamprofile['personastate'] = $_SESSION['steam_personastate'];
$steamprofile['realname'] = $_SESSION['steam_realname'];
$steamprofile['primaryclanid'] = $_SESSION['steam_primaryclanid'];
$steamprofile['timecreated'] = $_SESSION['steam_timecreated'];
$steamprofile['uptodate'] = $_SESSION['steam_uptodate'];
?>
答案 0 :(得分:0)
file_get_contents
- 使用https需要使用:
来自php.net
When using SSL, Microsoft IIS will violate the protocol by closing the
connection without sending a close_notify indicator. PHP will report
this as "SSL: Fatal Protocol Error" when you reach the end of the
data. To work around this, the value of error_reporting should be
lowered to a level that does not include warnings. PHP can detect
buggy IIS server software when you open the stream using the https://
wrapper and will suppress the warning. When using fsockopen() to
create an ssl:// socket, the developer is responsible for detecting
and suppressing this warning.