Question

I am trying to get the number of comments from a thread on Disqus, but the json_decoded response always returns NULL. If I echo $data before I json_decode it, I get a string that looks like valid JSON so I know the cURL request is working. What am I doing wrong? Here is my code:

$url = 'http://disqus.com/api/3.0/threads/details.json?forum=musicalfamilytree&thread=229671&api_key=key&callback=foo';

$session = curl_init($url);
curl_setopt($session, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($session);
curl_close($session);

// Decode JSON data
$results = json_decode($data, true);
if ($results === NULL) die('Error parsing json');
Was it helpful?

Solution

Remove callback=foo from the end of the URL; it causes the response to be JSON-P, which is not valid JSON.

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