For those of you who are looking to get started with the APIs but may not know PHP, I am posting an example that will help you get started.
This will retrieve a list of gamerDNA achievements and display them.
The code can be modified to suit your tastes.
PHP Code:
<?php
// URL of web service
$target_url = "http://helix.gamerdna.com/get_member_profile.php?member=<member name>&apikey=<api key from profile>";
// User Agent
$userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';
// Set up cURL parameters
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// Fetch the XML
$xml = curl_exec($ch);
// Nothing in $xml - display error.
if (!$xml)
{
echo "<br />cURL error number:" .curl_errno($ch);
echo "<br />cURL error:" . curl_error($ch);
exit;
}
// Load the resulting XML into a DOMDocument
$dom = new DOMDocument();
$dom->loadXML($xml);
$xpath = new DOMXPath($dom);
// Retrieve the achievement information
$achievements = $xpath->evaluate("/api/profile/achievements/achievement/name");
// Length of achievements found
echo $achievements->length." achievements found..";
// Name of achievements
for ($i = 0; $i < $achievements->length; $i++)
{
$achievement = $achievements->item($i);
echo "<br />Name of achievement: ".$achievement->nodeValue;
}
?>
Would love to hear from other programmers as far as tips / tricks / techniques in using the APIs.
Thanks and have a great day!
-brian