Getting PlaylistItems by Page Number in YouTube API? -


okay, lets have youtube playlist 500 items in them. youtube's playlistitems end-point allows retrieve 50 items @ time:

https://developers.google.com/youtube/v3/docs/playlistitems/list

after 50 items, gives nextpagetoken can use specify in query next page. doing this, iterate through entire playlist 500 items in 10 queries.

however, if wanted last page? page 10?

in youtube's v2 api, have told start index @ position 451, , give results 451-500. doesn't seem option in v3 api. now, seems if wanted page 10, have iterate through entire playlist once again, throw out first 9 pages, , take 10th page.

this seems huge waste of resources , curl operations alone killer.

so possible set starting index in v3 api in v2 api?

you can still use start index have generate corresponding page token yourself.

as far can tell observation, page tokens byte sequence encoded in base64, first byte being 8, , last 2 being 16, 0. generate tokens (using python 3):

i = 451 k = // 128 -= 128 * (k - 1) b = [8, index] if k > 1 or > 127: b += [k] b += [16, 0] t = base64.b64encode(bytes(f)).decode('utf8').strip('=') 

the hindmost operation removes trailing '=' characters used fill incomplete blocks in base64. result ('cmmdeaa') page token.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -