1

I referred to these links, How to get all the comments from Disqus? and Retrieving all comments from Disqus with PHP script to find out how to retrieve disqus comments.

But I keep getting these
(i) PHP Notice: Undefined variable: cursor on line 13
(ii) PHP Notice: Trying to get property of non-object on line 48

Below is the PHP Script:

<?php
ini_set('display_errors', 'on');
$key="API_SECRET_KEY";
$forum="tocsg";
$thread = 'link:http://www.theonlinecitizen.com/2015/10/how-far-can-pigs-fly/';
$limit = '100';

$endpoint = 'http://disqus.com/api/3.0/threads/listPosts.json?api_secret='.urlencode($key).'&forum='.$forum.'&limit='.$limit.'&thread='.$thread;        

//$cursor=null;

$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;
        $created = $comment->createdAt;
        $comment = $comment->message;
        // Get more data...

        echo "<p>".$name." wrote:<br/>";
        echo $comment."<br/>";
        echo $created."<br />";
        $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);
        }*/
    }
}

?>

I tried to use $cursor=null; to solve the first error. But second error still persist. Thank you in advance.

Community
  • 1
  • 1

1 Answers1

0

You use $cursor = '&cursor=' . $results->cursor->next; and try to get next from $cursor = $cursor->next;

Try this at line 31:

$cursor = $results->cursor->next;

Or this at line 48

$cursor = $results->cursor->next;
Puya Sarmidani
  • 1,226
  • 9
  • 26