I want to get all nextPageTokens in python youtube data api -


i'm trying nextpagetoken in youtube data api below code, want nextpagetokens. in loop, want reassign nextpagetoken

def get_next_videos():                                                                                                                                           while true:                                                                                                                                                      r = requests.get("https://www.googleapis.com/youtube/v3/search?part=snippet&maxresults=50&channelid="+channelid+"&order=date&key="+developer_key)              json_data = r.json()                                                                                                                                           nextpagetoken = json_data.get("nextpagetoken")                                                                                                                  second_r = requests.get("https://www.googleapis.com/youtube/v3/search?part=snippet&maxresults=50&channelid="+channelid+"&order=date&key="+developer_key+"\ &pagetoken="+nextpagetoken)                                                                                                                                        json_data = second_r.json()                                                                                                                                    nextpagetoken = json_data.get("nextpagetoken")                                                                                                                  third_r = requests.get("https://www.googleapis.com/youtube/v3/search?part=snippet&maxresults=50&channelid="+channelid+"&order=date&key="+developer_key+"&\ pagetoken="+nextpagetoken)                                                                                                                                         json_data = third_r.json()                                                                                                                                     nextpagetoken = json_data.get("nextpagetoken")                                                                                                                  fourth_r = requests.get("https://www.googleapis.com/youtube/v3/search?part=snippet&maxresults=50&channelid="+channelid+"&order=date&key="+developer_key+"\ &pagetoken="+nextpagetoken)                                                                                                                                        json_data = third_r.json()                                                                                                                                     nextpagetoken = json_data.get("nextpagetoken")  

assuming nextpagetoken won't returned when you're @ last page, do:

# first request r = requests.get("https://www.googleapis.com/youtube/v3/search?part=snippet&maxresults=50&channelid="+channelid+"&order=date&key="+developer_key) json_data = r.json()                                                                                                 nextpagetoken = json_data.get("nextpagetoken")  # retrieve rest of pages while nextpagetoken:     r = requests.get("https://www.googleapis.com/youtube/v3/search?part=snippet&maxresults=50&channelid="+channelid+"&order=date&key="+developer_key+"&pagetoken="+nextpagetoken)     json_data = r.json()     nextpagetoken = json_data.get("nextpagetoken") 

of course, inside loop, want collecting data you're retrieving in appropriate data structure (list, dictionary, etc.).


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -