2014-03-26 74 views
0

通過此鏈接,您可以從Dota的2 https://api.steampowered.com/IDOTA2Match_205790/GetMatchHistory/v001/?key=*獲得所有比賽** * ***如何通過steamid獲得用戶匹配?

,但如何通過steamid得到一個單用戶的比賽嗎?

+0

@Andy ACCOUNT_ID!= steamid – NickUnuchek

+0

@Andy如何通過用戶名或通過鏈接找到ACCOUNT_ID(http://steamcommunity.com/id/URLNAME)或PROFILE_ID http://steamcommunity.com/profiles/*** ***? – NickUnuchek

+0

我添加了一個關於如何從URL名稱獲取配置文件ID的答案的鏈接。 – Andy

回答

1

您需要做的第一件事是將STEAM ID轉換爲PROFILE ID。這可以使用諸如Steam Condenser項目之類的東西來完成,更簡單的是蒸汽冷凝器項目中的function。如果你只是使用這個函數,你將不得不修改拋出的異常,因爲SteamCondenserException將不存在。如果您有獨特的玩家ID,我建議您使用整個蒸汽冷凝器項目並查看此answer

/** 
* Converts a SteamID as reported by game servers to a 64bit numeric 
* SteamID as used by the Steam Community 
* 
* @param string $steamId The SteamID string as used on servers, like 
* <var>STEAM_0:0:12345</var> 
* @return string The converted 64bit numeric SteamID 
* @throws SteamCondenserException if the SteamID doesn't have the correct 
* format 
*/ 
    public static function convertSteamIdToCommunityId($steamId) { 
     if($steamId == 'STEAM_ID_LAN' || $steamId == 'BOT') { 
      throw new SteamCondenserException("Cannot convert SteamID \"$steamId\" to a community ID."); 
     } 
     if (preg_match('/^STEAM_[0-1]:[0-1]:[0-9]+$/', $steamId)) { 
      $steamId = explode(':', substr($steamId, 8)); 
      $steamId = $steamId[0] + $steamId[1] * 2 + 1197960265728; 
      return '7656' . $steamId; 
     } elseif (preg_match('/^\[U:[0-1]:[0-9]+\]$/', $steamId)) { 
      $steamId = explode(':', substr($steamId, 3, strlen($steamId) - 1)); 
      $steamId = $steamId[0] + $steamId[1] + 1197960265727; 
      return '7656' . $steamId; 
     } else { 
      throw new SteamCondenserException("SteamID \"$steamId\" doesn't have the correct format."); 
     } 
    } 

現在,你有64位ID,您可以通過這個API調用你已經做。它將傳遞給account_id參數。

在PHP中,你最終會像這樣的東西:

$matches = 10; // Return last 10 matches 
$acct = convertSteamIdToCommunityId(STEAMIDYOUARECHECKING); 
$APIKEY = <YOURKEYHERE>; 

$steamurl = "https://api.steampowered.com/IDOTA2Match_570/GetMatchHistory/V001/?key=$APIKEY&account_id=$acct&Matches_Requested=$matches&format=json"; 
$json_object= file_get_contents($steamurl); 
header('Content-Type: application/json'); 
echo $json_object; 

在該段頂部的三個變量您與匹配的數量填寫你要回來,蒸汽ID您正在檢查您正在使用的API KEY。你的結果將在$json_object中,供你解析。

+0

例如我的鏈接是http://steamcommunity.com/profiles/76561198125073633/ 如何獲取account_id? – NickUnuchek

+0

哦對不起,它已經蒸汽76561198125073633 – NickUnuchek