Need Help with Disqus 3.0 API cursor with PHP

318 views
Skip to first unread message

Peter C.

unread,
Apr 11, 2013, 1:15:48 AM4/11/13
to disqu...@googlegroups.com
Hi folks:

I'm interested in dispalying Disqus discussion messages in a widget that uses PHP and that will show on my website.
The widget will cycle through a large amount of messages (currently a few thousand messages). 

I've succeeded in using PHP to pull the discussion messages through the Disqus Version 3.0 API using PHP CURL and outputing, but I haven't
figured out to how use the Disqus cursor in the 3.0 API. I've read the documentation at http://disqus.com/api/docs/cursors/ and also did many 
google and other online searches to find answers but there is no documenation on how to do this with the 3.0 API.

It looks like the current Disqus 3.0 API has a very limited cursor and paginator feature. 

For example, I need to run a disqus cursor that can pull 100 Discussion messages at a time. If I had 2,000 total discussion
messages, I would need to call this cursor/paginator to pull 100 messages at a time and then output these 100 messages
on my PHP widget. 

 Ideally the Disqus cursor and paginator would work like this:

while($cursor.hasNext()){
//call disqus API cursor/paginator method that goes through the 2,000 messages in 100 blocks at a time, Disqus cursor code here... 

// get discussion messages using CURL and input into an array called $hundred...

//output the array $hundred onto my website over a pre-set time duration.
for ($i = 0; $i < 100; i++)
{
doSomething($hundred[$i]);
}

}

Can someone provide Disqus API 3 code examples to do this with PHP? Is the 3.0 API library developed enough to have a decent cursor and paginator feature?   Please help!

Thanks.


Peter  (in Canada)


Burak Yiğit Kaya

unread,
Apr 11, 2013, 2:21:23 AM4/11/13
to disqu...@googlegroups.com
The example in the API documentation should be pretty clear: if you have cursor.hasNext `true` then get cursor.next value and send it as the cursor parameter with your next request. Rinse & repeant until you reach hasNext = fase.
GET /api/3.0/posts/list.json?
    public_key=PUBLIC_KEY&
    cursor=1320872487989935:0:0





--
You received this message because you are subscribed to the Google Groups "Disqus Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to disqus-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
BYK

Peter C.

unread,
Apr 12, 2013, 12:11:59 AM4/12/13
to disqu...@googlegroups.com
Hi Burak,


Thank you for the info. Can you clarify about what parameters the API JSON cursor accepts?

You gave the example of GET /api/3.0/posts/list.json?public_key=PUBLIC_KEY&cursor=1320872487989935:0:0

What exact is the ID# in cursor=1320872487989935:0:0?  Is this an actual cursor position # or a thread number or something else?

Also, is there a way I can call cursor without this ID number? 

For example, I've written PHP script where I made a JSON calls.  I would like to start to cursor through latest results based on "Since" last time and date of last access, for example:
https://disqus.com/api/3.0/threads/list?api_key="My API KEy"&forum="My Forum Name"&since=2013-01-01T00:00:26&order=asc&cursor.hasNext=true;

What are some ways that I can add the cursor to a JSON call such as above? Thanks for your help.


Peter

Burak Yiğit Kaya

unread,
Apr 12, 2013, 12:34:53 PM4/12/13
to disqu...@googlegroups.com
Hi Peter,

A cursor defines where you left while fetching a large array of resources. Think the posts as a book and the cursor as a bookmark. When you make your first call, without a cursor(since you start from the beginning). you don't pass a cursor. And the response has a cursor object where cursor.hasNext tells you if there's more and cursor.next tells you where to start from if you want to get the next batch of posts. So you get that value, it is your bookmark, and then pass it to the server using the parameter name "cursor". Then the server says "oh, this is where you left? here are the remaining X posts" and gives you another batch. If that batch is not the final, you will again have cursor.hasNext true in the response and a cursor.next which is different from the first one since the place(or page if you liked the book anology) you are at now is different.

Does this make sense?

Best,


--
You received this message because you are subscribed to the Google Groups "Disqus Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to disqus-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
BYK

Peter C.

unread,
Apr 13, 2013, 2:32:08 AM4/13/13
to disqu...@googlegroups.com
Yes, thanks for the explanation.
Reply all
Reply to author
Forward
0 new messages