Question

I'm new to JSON and APIs and I want to make a PHP CLI script that will use StackOverflow API. I've made myself a key and this is my code so far:

<?php

//Call stack API .$key
$google_url = "http://api.stackoverflow.com/1.1/stats";

//Get and Store API results into a variable
$result = file_get_contents($google_url);
//$jsonArray = json_decode($result);
print_r($result);
//var_dump($jsonArray);

?>

But the print_r($result); returns some strange characters. I can't read it could you give me some info? Any help will be appreciated. The whole project will be an open source search engine about StackOverflow posts and comments!

Was it helpful?

Solution

You need to un gzip it even if you didn't send an accept: gzip header in the http request, because all responses are gzip'd

see How can I read GZIP-ed response from Stackoverflow API in PHP?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top