Showing Posts For JonnyTen.9428:
Here’s something extremely simple for the curious PHP beginners that simply want a quick result. Wouldn’t recommend building on this method though:
function getItem($id) {
$response = file_get_contents(“https://api.guildwars2.com/v1/item_details.json?item_id=”.$id);
$response = json_decode($response, false);
return $response;
}
//Use as following:
echo getItem(12345)->name;
Alternatively I use the HttpRequest class
function getItem($id)
{
$req = new HttpRequest(‘https://api.guildwars2.com/v1/item_details.json’, HttpRequest::METH_GET);
//Add GET values, in this case just the item_id and language
$req->addQueryData(array(
‘item_id’ => $id,
‘lang’ => ‘en’
));
try {
//Sends it and fills $result Object
$result = $req->send();
//If any errors
} catch (HttpException $ex) {
echo $ex;
}
return ($result);
}
print_r(getItem(12345));
(edited by JonnyTen.9428)