Steem.js Example #3. Get Posts more than 20 posts, pagination.

WordPress Post : http://junn.net/archives/575

Github source :

  1. https://github.com/junn279/steemjs_example/blob/master/steem03_1.php (lite version)
  2. https://github.com/junn279/steemjs_example/blob/master/steem03.php

 

Continue to our previous example, this time I’ll introduce get_discussions_… functions.

I don’t know why, but functions are named like as below.

์ง€๋‚œ ํฌ์ŠคํŒ…์— ์ด์–ด, get_discussion ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด 20๊ฐœ ์ด์ƒ์˜ ์ž๋ฃŒ, ์—ฐ์†๋˜๋Š” ์ž๋ฃŒ ๋ฐ›๊ธฐ๋ฅผ ํ™•์ธํ•ด๋ณผ ์˜ˆ์ •์ด๋‹ค. ํ•จ์ˆ˜ ์ด๋ฆ„์„ ์™œ discussion์ด๋ผ๊ณ  ํ–ˆ๋Š”์ง€ ์ž˜ ๋ชจ๋ฅด๊ฒ ๋‹ค.

At this time, make a source like this. A Little bit different from previous sources, but this is more effective to view sequential 10, 20 (next 10) posts. I used getDiscussionsByCreated. Literally, byCreated means ‘retrieve posts in the order when they were created.

Look atย  ‘query’ and number of ‘limit’ is 11 not 10. Last one is for ‘retrieve next 10 posts’

๊ธฐ๋ณธ ํ‹€์„ ์œ„๊ณผ ๊ฐ™์ด ์žก๋Š”๋‹ค. ์ผ๋‹จ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๊ฐฏ์ˆ˜๋ฅผ 11๋กœ ํ•œ ๊ฒƒ์€, ๋งˆ์ง€๋ง‰ ๋ฐ์ดํ„ฐ๋Š” ๋‹ค์Œ 10๊ฐœ๋ฅผ ๋ถˆ๋Ÿฌ์–ด์˜ค๊ธฐ ์œ„ํ•œ ๋ฐ์ดํ„ฐ๋กœ ํ•„์š”ํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

As member variation of ‘query’ object, set start_author and start_permlink from last 11th post(but array index starts from number zero, so number 10 indicate the 11th post).

And then if you watch the developer console, you can see the retrieved posts.

But in this case, you should not put ‘inner query2~steem.api.getDis.. function’ out of first getDiscussionBy… function. Because steem.api is running synchronously.

I’m sure there is another way to run these sequential functions asynchronously. But I don’t know yet.

๋ฐ›์•„์˜จ ๋ฐ์ดํ„ฐ์˜ ๋งˆ์ง€๋ง‰(11๋ฒˆ์งธ; array์—์„œ index๋Š” 10) ํฌ์ŠคํŠธ์˜ ์ž๋ฃŒ๋ฅผ ์ด์šฉํ•ด์„œ ๋‹ค์Œ ๋‚ด์šฉ์„ ๋ถˆ๋Ÿฌ์˜จ๋‹ค. ํ•จ์ˆ˜ ๋‚ด๋ถ€์— ๋‹ค์‹œ ํ•จ์ˆ˜๋ฅผ ๋„ฃ์–ด์•ผํ•˜๋Š” ์ด์œ ๋Š” ๋™๊ธฐํ™”๋กœ ์ง„ํ–‰๋˜๋Š” ํ•จ์ˆ˜์ด๊ธฐ ๋•Œ๋ฌธ์— ๋ฐ–์œผ๋กœ ๋บ„ ๊ฒฝ์šฐ ์ œ๋Œ€๋กœ๋œ ๋ณ€์ˆ˜๊ฐ’์ด ์„ธํŒ…๋˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

 

Finally, I made a source using this function, put a button and by using it, we can get next 10 posts.

๋งˆ์ง€๋ง‰์œผ๋กœ ๋งŒ๋“  ์†Œ์Šค๋Š” ๋ฒ„ํŠผ์„ ์ด์šฉํ•ด์„œ ๊ณ„์†์ ์œผ๋กœ ํฌ์ŠคํŠธ๋ฅผ ์—ฐ์žฅํ•˜๋Š” ์†Œ์Šค์ด๋‹ค.

https://github.com/junn279/steemjs_example/blob/master/steem03.php

There is a ‘click’ button, and then you can get next 10 posts. These are match to what we can see through https://steemit.com/created/kr perfectly. (Be sure to be different from my result)

์•„๋ž˜์™€ ๊ฐ™์€ ๊ฒฐ๊ณผ๋ฅผ ๋งŒ๋“ค์–ด๋‚ด์—ˆ๋‹ค.

 

0 Shares:
1 comment
Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.