API script for gamercards
After hours and hours of searching I finally found an API script for gamercards. Only problem is this freaking 开发者_如何转开发thing updates every 30 minutes. If I open a new browser and go to the URL I get the most recent updated info. Is there a way to trick this thing to think each refresh is a new browser session?
http://xboxapi.duncanmackenzie.net/gamertag.ashx?GamerTag=gamerholics
Here's the script.
<?php
$ch = curl_init("http://xboxapi.duncanmackenzie.net/gamertag.ashx?GamerTag=gamerholics");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);
$data = curl_exec($ch);
curl_close($ch);
$xml = new SimpleXmlElement($data, LIBXML_NOCDATA);
foreach ($xml->PresenceInfo as $mystatus)
{
print '<div id="xboxlivestatus"><a href="' . $xml->ProfileUrl . '">' . $xml->Gamertag . '</a> is ' . $mystatus->StatusText . ' : ' . $mystatus->Info . ' : ' . $mystatus->Info2. '</div>';
}
?>
If your curl is storing cookies somewhere, then most likely it's keeping a cookie around that's giving you the 30 minute timeout. Try using
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
to force session cookies (so they wipe after each run). As well, investigate if there's a cookie jar file somewhere, which you might have to wipe seperately to truly force a new session with the API each time.
精彩评论