好吧,我正在使用 Bungie 的 Halo Reach API。现在,我的代码将获取特定玩家的所有游戏 ID。
我想将游戏 ID 存储在 mysql 数据库中,然后将来如果玩家想要更新数据库,脚本只会获取数据库中尚不存在的游戏 ID。
脚本获取最近的页面$iPage = '0';
然后如果HasMorePages
等于 true,它将获取下一页$iPage++
,直到HasMorePages
为 false。每页提供 25 个游戏 ID,最后一页可能少一些。
所以基本上我想获得第一次运行脚本时不存在的游戏 ID,而不是对 API 进行不必要的调用。我怎么能那样做?
<?php
include_once('sql.php'); // MySQL Connection
include_once('api.php'); // API unique identifer string
$gamertag = 'jam1efoster'; // Gamertag
$variant = 'Unknown'; // Unknown gets all game variants
$iPage = '0'; // 0 is the most recent page
while(!$endPages == true){
$GetGameHistory = "http://www.bungie.net/api/reach/reachapijson.svc/player/gamehistory/".$apiKey."/".rawurlencode(strtolower($gamertag))."/".$variant."/".$iPage;
$output = file_get_contents($GetGameHistory);
$obj = json_decode($output);
//echo $output;
$mPages = $obj->HasMorePages;
if($mPages == false){$endPages = true;}
foreach($obj->RecentGames as $recentgames) {
$gameId = $recentgames->GameId;
//echo $gameId.'<br />';
}
//echo $iPage.'<br />';
$iPage++;
}
?>