-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do you get all the threads listed? #17
Comments
I'll share with you a snipet of the the way i use to get comments from Disqus in a symfony 2 project. more documentation can be found here : http://disqus.com/api/docs/posts/list/ NB: I'm using Guzzle bundle (like cURL), the instance is '$this->client' public function fetchComment($thread, $order, $cursor, $limit = 100)
this is the function to build the tree comments (each answer message is under the first message it's related to) protected function buildTreeComment(array &$comments, array &$treeComments, $currentParentId = 0)
hope it helps |
Other solution is to modify the library: return $data->response; use return $data; that way you will have access to cursor information see https://disqus.com/api/docs/cursors/ PS: their console is broken it send limit instead of cursor so you can't test if this work there. |
after removing ->response I use this code to fetch all data. function save($fname, $obj) {
$f = fopen($fname, 'w');
fwrite($f, json_encode($obj, JSON_PRETTY_PRINT));
fclose($f);
}
require('disqusapi/disqusapi.php');
$disqus = new DisqusAPI('<SECRET>');
function fetch($options, $fn, $cursor = NULL) {
if ($cursor != NULL) {
$payload = array_merge($options, array('cursor' => $cursor));
} else {
$payload = $options;
}
$res = $fn($payload);
$posts = $res->response;
if ($res->cursor->hasNext) {
$posts = array_merge($posts, fetch($options, $fn, $res->cursor->next));
}
return $posts;
}
$opts = array('forum' => '<name>'); // if you have lot of data use 'limit' => 100
save('posts.json', fetch($opts, function($payload) use ($disqus) {
return $disqus->posts->list($payload);
}));
save('threads.json', fetch($opts, function($payload) use ($disqus) {
return $disqus->threads->list($payload);
})); |
How do you get all the threads listed?
I can't figure out the cursor.
Here's my code:
function listThreads($cursor,$incurrences) {
global $setting;
global $disqus;
$incurrences = $incurrences+1;
$params = array('forum' => $setting['disqus_forum'], 'order' => 'desc', 'limit' => 90);
if($cursor != 0) {
$params['cursor'] = $cursor;
}
echo $cursor.'
';
$i = 0;
$threads = $disqus->threads->list($params);
$cursor = $cursor+90;
foreach ($threads as $thread) {
$i = $i+1;
$id = $thread->id;
$title = $thread->title;
$link = $thread->link;
$date = date('Y-m-d H:i:s',strtotime($thread->createdAt."+0000"));
if(mysql_num_rows(mysql_query("SELECT * FROM
disqus_threads
wherethread_id
= '$id' andtitle
= '$title'")) == 0) {$insert = mysql_query("INSERT INTO
disqus_threads
(thread_id
,title
,link
,date
) VALUES ('$id','$title','$link','$date')") or die(mysql_error());}
}
The text was updated successfully, but these errors were encountered: