【问题标题】:disqus cursor - Trying to get property of non-objectdisqus cursor - 试图获取非对象的属性
【发布时间】:2015-12-04 10:38:29
【问题描述】:

我参考了这些链接How to get all the comments from Disqus?Retrieving all comments from Disqus with PHP script 来了解如何检索disqus cmets。

但我不断得到这些
(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;解决第一个错误。但第二个错误仍然存​​在。提前谢谢你。

【问题讨论】:

  • 我猜你需要检查 hasNext 是否为真。否则,您正在寻找不存在的下一个。

标签: php disqus


【解决方案1】:

您使用$cursor = '&amp;cursor=' . $results-&gt;cursor-&gt;next; 并尝试从$cursor = $cursor-&gt;next; 获取下一个

在第 31 行试试这个:

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

或者这个在第 48 行

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-09
    相关资源
    最近更新 更多