php - Youtube Data API v3 pageToken for arbitrary page -


another question on revealed pagetokens identical different searches, provided page number , maxresults settings same.

version 2 of api let go arbitrary page setting start position, v3 provides next , previous tokens. there's no jumping page 1 page 5, if know there 5 pages of results.

so how work around this?

a youtube pagetoken 6 characters long. here's i've been able determine format:

char 1: 'c' i've seen. char 2-3: encoded start position char 4-5: 'qa' i've seen. char 6: 'a' means list items in position greater or equal start position. 'q' means list items before start position.

due nature of character 6, there 2 different ways represent same page. given maxresults=1, page 2 can reached setting page token either "caeqaa" or "caiqaq". first 1 means start @ result number 2 (represented characters 2-3 "ae") , list 1 item. second means return 1 item before result number 3 (represented characters 2-3 "ai".

characters 2-3 strange base 16 encoding.

character 3 uses list a-z, a-z, 0-9 , increments 4 in list each increase of 1. series a,e,i,m,q,u,y,c,g,k,o,s,w,0,4,8. character 2 goes b c d , on. purposes, i'm not working large result sets, haven't bothered see happens second character beyond couple hundred results. perhaps working larger sets provide update how character 2 behaves after that.

since string contains start position , option ">=" or "<", same string used in multiple cases. instance, 2 results per page, start position of second page result 3. pagetoken "caiqaa". identical token third page 1 result per page.

since i'm php person, here's function i'm using pagetoken given page:

function token($limit, $page) {     $start = 1 + ($page - 1) * $limit;     $third_chars = array_merge(             range("a","z",4),             range("c","z",4),             range(0,9,4));     return 'c'.            chr(ord('a') + floor($start / 16)).            $third_chars[($start % 16) - 1].            'qaa'; } $limit = 1; echo "with $limit result(s) per page...".php_eol; ($i = 1; $i < 6; ++$i) {     echo "the token page $i ".token($limit, $i).php_eol; } 

please test function in project , update rest of if find flaw or enhancement since youtube hasn't provided easy way this.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -