disqus cursor - 试图获取非对象的属性

时间:2015-12-04 10:38:29

标签: php disqus

我提到了这些链接How to get all the comments from Disqus?Retrieving all comments from Disqus with PHP script,以了解如何检索disqus评论。

但我一直得到这些 (i)PHP注意:未定义的变量:光标在第13行上 (ii)PHP通知:试图在第48行获得非对象的财产

下面是PHP脚本:

<?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);
        }*/
    }
}

?>

我尝试使用$ cursor = null;解决第一个错误。但第二个错误仍然存​​在。提前谢谢。

1 个答案:

答案 0 :(得分:0)

您使用$cursor = '&cursor=' . $results->cursor->next;并尝试从$cursor = $cursor->next;

获取下一个

在第31行尝试此操作:

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

或者第48行

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