我正试图使用Disqus api从论坛帖子中提取所有评论。 但是我还没有成功,因为我对PHP没什么经验。
我已经创建了一个api,但我不知道提取评论的正确方法。 有人可以帮助我吗?
我正在使用OctoberCms,在页面上,我的标记看起来像这样:
<div class="container">
<div class="row">
<h1>recensie's test</h1>
<br>
{{ this.page.myVar }}
</div>
我在代码选项卡上的代码如下所示:
function onStart()
{
$this->page["myVar"] = "Hello World!";
ini_set('display_errors', 'on');
$key="*my_public_key*";
$forum="lange-allround-service";
$thread = '1153c594c77347169f40cb7e639ea5f5';
$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);
}*/
}
}