Disqus API包含使用在JSON響應中返回的遊標的分頁方法。看到這裏有關遊標的信息:http://disqus.com/api/docs/cursors/
既然你提到的PHP,這樣的事情應該讓你開始:
<?php
$apikey = '<your key here>'; // get keys at http://disqus.com/api/ — can be public or secret for this endpoint
$shortname = '<the disqus forum shortname>'; // defined in the var disqus_shortname = '...';
$thread = 'link:<URL of thread>'; // IMPORTANT the URL that you're viewing isn't necessarily the one stored with the thread of comments
//$thread = 'ident:<identifier of thread>'; Use this if 'link:' has no results. Defined in 'var disqus_identifier = '...';
$limit = '100'; // max is 100 for this endpoint. 25 is default
$endpoint = 'https://disqus.com/api/3.0/threads/listPosts.json?api_key='.$apikey.'&forum='.$shortname.'&limit='.$limit.'&cursor='.$cursor;
$j=0;
listcomments($endpoint,$cursor,$j);
function listcomments($endpoint,$cursor,$j) {
// Standard CURL
$session = curl_init($endpoint.$cursor);
curl_setopt($session, CURLOPT_RETURNTRANSFER, 1); // instead of just returning true on success, return the result on success
$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 = $results->cursor;
$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);
/* uncomment to only run $j number of iterations
$j++;
if ($j < 10) {
listcomments($endpoint,$cursor,$j);
}*/
}
}
?>
非常感謝!但是,我們需要準確地爲$ thread(線程的URL)和$ cursor?順便說一句,我們最多隻能有100條評論嗎? – 2013-02-26 09:15:23
線程的URL只是註釋頁面的URL。在這種情況下,它是http://www.cnn.com/2013/02/25/tech/innovation/google-glass-privacy-andrew-keen/index.html - 遊標值從API響應中提取,並且代表下一組100條評論。該腳本將一直持續到沒有其他評論爲止。 – 2013-02-27 05:39:14
我將$ shortname設置爲'cnn'(var disqus_shortname ='cnn';)和$ thread''鏈接:'並保持$ cursor爲空,但事實證明「Error parsing json」。我想念什麼? –
2013-02-27 07:11:14