Take the 2-minute tour ×

Im trying to use the GiantBomb api to query video games, and currently when I enter the URL into a browser, it works just fine. The Json data shows up.

Heres an example url.. http://www.giantbomb.com/api/search/?api_key=83611ac10d0dfghfgh157177ecb92b0a5a2350c59a5de4&query=Mortal+Kombat&format=json

But when I try to use my php wrapper that Im just starting to build, it returns html?? Heres the start of my wrapper code....(very amateur for now)

You'll notice in the 'request' method, Ive commented out the return for json_decode($url), because when I uncomment it, the page throws a 500 error??? So I wanted to see what happends when I just echo it. And it echos an html page. Surely it should just echo what is shown, when you just enter that url into the browser, no?

However...if I replace the url with say a GoogleMap url, it echoes out Json data just fine, without using json_decode. Any ideas as to wahts going on here????

class GiantBombApi {

public $api_key;
public $base_url;
public $format;

 function __construct() {
$this->api_key = "83611ac10d0d157177ecb92b0a5a2350c59a5de4";
$this->search_url = "http://www.giantbomb.com/api/search/?api_key=".$this- >api_key."&query=";


public function search($query){
$query = urlencode($query);
$url = $this->search_url.$query.$this->format;
return $this->request($url);

public function request($url) {
$response = file_get_contents($url);
echo $response;
//return json_decode($response, true);


   $games = new GiantBombApi;
   $query = $_GET['search'];
   echo $games->search($query);
share|improve this question

1 Answer 1

up vote 1 down vote accepted

I ran a few requests through Postman and it seems that the api looks at the mime-type as well as the query string. So try setting a header of "format" to "json".

share|improve this answer
Thanks! Something so simple...didnt even think about it....lol –  KyleK Apr 5 '13 at 22:49

Your Answer


