11/DEC/13

Winter!: Prepare for holiday gaming!


Forums top   gamerDNA.com Forums > gamerDNA.com > Helix Developers/API (Beta)


Thread Tools
  #1  
Old 05-21-2009, 10:46 PM
brianchilders's Avatar
brianchilders brianchilders is offline
Member
 
Join Date: Apr 2009
Location: Kenosha, WI
Posts: 1
brianchilders is community member of note
Post Example PHP Code
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($chCURLOPT_USERAGENT$userAgent);
curl_setopt($chCURLOPT_URL,$target_url);
curl_setopt($chCURLOPT_FAILONERRORtrue);
curl_setopt($chCURLOPT_FOLLOWLOCATIONtrue);
curl_setopt($chCURLOPT_AUTOREFERERtrue);
curl_setopt($chCURLOPT_RETURNTRANSFER,true);
curl_setopt($chCURLOPT_TIMEOUT10);
// 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
Reply With Quote
  #2  
Old 05-26-2009, 08:18 AM
RDaneel's Avatar
RDaneel RDaneel is offline
Member
 
Join Date: May 2009
Location: Not in Kansas
Posts: 10
RDaneel is a jewel in the community
I'd say it's Greek to me, but it's actually more like COBOL to me.
Reply With Quote
Post Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off