php - Why is JSON not being returned from GiantBomb API -
im trying use giantbomb api query video games, , when enter url browser, works fine. json data shows up.
heres example url.. http://www.giantbomb.com/api/search/?api_key=83611ac10d0dfghfgh157177ecb92b0a5a2350c59a5de4&query=mortal+kombat&format=json
but when try use php wrapper im starting build, returns html?? heres start of wrapper code....(very amateur now)
you'll notice in 'request' method, ive commented out return json_decode($url), because when uncomment it, page throws 500 error??? wanted see happends when echo it. , echos html page. surely should echo shown, when enter url browser, no?
however...if replace url googlemap url, echoes out json data fine, without using json_decode. ideas wahts going on here????
class giantbombapi { public $api_key; public $base_url; public $format; function __construct() { $this->format="&format=json"; $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); } } //testing section $games = new giantbombapi; $query = $_get['search']; echo $games->search($query);
i ran few requests through postman , seems api looks @ mime-type query string. try setting header of "format" "json".
Comments
Post a Comment