I want to get all nextPageTokens in python youtube data api -
i'm trying nextpagetoken
in youtube data api below code, want nextpagetoken
s. 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
Post a Comment