title: disqus cursor - Trying to get property of non-object
body: <p>I referred to these links, <a href="https://stackoverflow.com/questions/15080258/how-to-get-all-the-comments-from-disqus?rq=1">How to get all the comments from Disqus?</a> and <a href="https://stackoverflow.com/questions/16332080/retrieving-all-comments-from-disqus-with-php-script">Retrieving all comments from Disqus with PHP script</a> to find out how to retrieve disqus comments. </p>
  
  <p>But I keep getting these<br>
  (i) PHP Notice: Undefined variable: cursor on line 13<br>
  (ii) PHP Notice:  Trying to get property of non-object on line 48  </p>
  
  <p>Below is the PHP Script:</p>
  
  <pre><code>&lt;?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).'&amp;forum='.$forum.'&amp;limit='.$limit.'&amp;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-&gt;response;
  
      // Cursor for pagination
      $cursor = '&amp;cursor=' . $results-&gt;cursor-&gt;next;
  
      $i=0;
      foreach ($comments as $comment) {
          $name = $comment-&gt;author-&gt;name;
          $created = $comment-&gt;createdAt;
          $comment = $comment-&gt;message;
          // Get more data...
  
          echo "&lt;p&gt;".$name." wrote:&lt;br/&gt;";
          echo $comment."&lt;br/&gt;";
          echo $created."&lt;br /&gt;";
          $i++;
      }
  
      // cursor through until today
      if ($i == 100) {
          $cursor = $cursor-&gt;next;
          $i = 0;
          listcomments($endpoint,$cursor,$j);
          /* uncomment to only run $j number of iterations
          $j++;
          if ($j &lt; 10) {
              listcomments($endpoint,$cursor,$j);
          }*/
      }
  }
  
  ?&gt;
  </code></pre>
  
  <p>I tried to use $cursor=null; to solve the first error. But second error still persist. Thank you in advance.</p>