Получение всех комментариев от Disqus с помощью скрипта PHP

У меня есть PHP-скрипт, который я нашел, и я пытаюсь использовать для получения комментариев из потока блога, кажется, все есть, но я не могу понять, почему он работает неправильно. Я продолжаю получать эту ошибку

Warning: Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/AP-Get.php on line 33 

Вот сценарий:

 <?php ini_set('display_errors', 'on'); $key="KEY-OMITTED"; $forum="amandapalmer"; $thread = '1009158814'; $limit = '100'; $endpoint = 'http://disqus.com/api/3.0/threads/listPosts.json?api_key='.urlencode($key).'&forum='.$forum.'&limit='.$limit.'&cursor='.$cursor; $j=0; listcomments($endpoint,$cursor,$j); function listcomments($endpoint,$cursor,$j) { // Standard CURL $session = curl_init($endpoint.$cursor); curl_setopt($session, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($session); curl_close($session); // Decode JSON data $results = json_decode($data); if ($results === NULL) die('Error parsing json'); // Comment response $comments = $results->response; // Cursor for pagination $cursor = $results->cursor; $i=0; foreach ($comments as $comment) { $name = $comment->author->name; $comment = $comment->message; $created = $comment->createdAt; // Get more data... echo "<p>".$name." wrote:<br/>"; echo $comment."<br/>"; echo $created."</p>"; $i++; } // cursor through until today if ($i == 100) { $cursor = $cursor->next; $i = 0; listcomments($endpoint,$cursor); /* uncomment to only run $j number of iterations $j++; if ($j < 10) { listcomments($endpoint,$cursor,$j); }*/ } } ?> 

Я подумал, что это был мой ключ API, но я несколько раз проверял его на других более простых сценариях для Disqus, и он отлично работает на этих сценариях.

    Основная проблема заключалась в том, что конечная точка API «threads / listPosts» требует, чтобы вы указали поток, поэтому произошел ответ об отказе. Я исправил некоторые другие возможные проблемы со сценарием и получил его работу (см. Код ниже).

    Обратите внимание, что эта версия использует ваш секретный ключ. Чтобы использовать ваш открытый ключ, измените «api_secret» на «api_key».

     <?php ini_set('display_errors', 'on'); $key="API-SECRET-KEY"; $forum="amandapalmer"; $thread = '1009158814'; $limit = '100'; $endpoint = 'http://disqus.com/api/3.0/threads/listPosts.json?api_secret='.urlencode($key).'&forum='.$forum.'&limit='.$limit.'&thread='.$thread; $j=0; listcomments($endpoint,$cursor,$j); function listcomments($endpoint,$cursor,$j) { // Standard CURL $session = curl_init($endpoint.$cursor); curl_setopt($session, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($session); curl_close($session); // Decode JSON data $results = json_decode($data); if ($results === NULL) die('Error parsing json'); // Comment response $comments = $results->response; // Cursor for pagination $cursor = '&cursor=' . $results->cursor->next; $i=0; foreach ($comments as $comment) { $name = $comment->author->name; $comment = $comment->message; $created = $comment->createdAt; // Get more data... echo "<p>".$name." wrote:<br/>"; echo $comment."<br/>"; echo $created."</p>"; $i++; } // cursor through until today if ($i == 100) { $cursor = $cursor->next; $i = 0; listcomments($endpoint,$cursor,$j); /* uncomment to only run $j number of iterations $j++; if ($j < 10) { listcomments($endpoint,$cursor,$j); }*/ } } ?> конечные <?php ini_set('display_errors', 'on'); $key="API-SECRET-KEY"; $forum="amandapalmer"; $thread = '1009158814'; $limit = '100'; $endpoint = 'http://disqus.com/api/3.0/threads/listPosts.json?api_secret='.urlencode($key).'&forum='.$forum.'&limit='.$limit.'&thread='.$thread; $j=0; listcomments($endpoint,$cursor,$j); function listcomments($endpoint,$cursor,$j) { // Standard CURL $session = curl_init($endpoint.$cursor); curl_setopt($session, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($session); curl_close($session); // Decode JSON data $results = json_decode($data); if ($results === NULL) die('Error parsing json'); // Comment response $comments = $results->response; // Cursor for pagination $cursor = '&cursor=' . $results->cursor->next; $i=0; foreach ($comments as $comment) { $name = $comment->author->name; $comment = $comment->message; $created = $comment->createdAt; // Get more data... echo "<p>".$name." wrote:<br/>"; echo $comment."<br/>"; echo $created."</p>"; $i++; } // cursor through until today if ($i == 100) { $cursor = $cursor->next; $i = 0; listcomments($endpoint,$cursor,$j); /* uncomment to only run $j number of iterations $j++; if ($j < 10) { listcomments($endpoint,$cursor,$j); }*/ } } ?>