如何更新游戏历史数据库? Bungie Halo Reach API

| 好吧,我正在使用Bungie的Halo Reach API。现在,我的代码将获取特定玩家的所有游戏ID。 我想将游戏ID存储在mysql数据库中,然后在将来,如果玩家想要更新数据库,则脚本将仅获取数据库中尚未存在的游戏ID。 脚本获取最新页面
$iPage = \'0\';
然后,如果
HasMorePages
等于true,则获得下一页
$iPage++
,直到
HasMorePages
为假。 每个页面提供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++;
}

?>
    
已邀请:
考虑到我了解您正在尝试做什么以及您正在问什么。试试这个代码:
<?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
// get current ids
$result=mysql_query(\'SELECT ALL CURRENT IDS\');// PUT YOUR SQL HERE !
$oldIds=array();
$newIds=array();
while($row=mysql_fetch_array($result))$oldIds[]=$row[\'id\'];// might be different in your scenario
// get all ids, unfortunately
for(;;){
    $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);
    // get fresh ids
    foreach($obj->RecentGames as $recentgames) {
        if(in_array($recentgames->GameId, $oldIds))continue;// we already have this id
        $newIds[]=$recentgames->GameId;
    }

    if(!$obj->HasMorePages)break;// no more pages? break!
    $iPage++;
}

var_dump($newIds);
?>
我不熟悉Bungie的方法,可能是将游戏推向api。如果已订购,请发表评论。我将修改我的代码。如果他们很武断,那真是不幸。     

要回复问题请先登录注册