Я бы хотел получить all видео из YouTube API для данного ChannelId с использованием Python.Ниже приведен код, который я пробовал, но я не могу понять, как добавить данные в цикл while.
all
ChannelId
while
import requests import json mykey = 'myGoogleKey' channelid = 'someRandomChannelId' # First request r = requests.get("https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=50&channelId="+channelid+"&order=date&key="+mykey) json_data = r.json() nextPageToken = json_data.get("nextPageToken") # Retrieve all the rest of the pages while nextPageToken: r = requests.get("https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=50&channelId="+channelid+"&order=date&key="+mykey+"&pageToken="+nextPageToken) json_data.append(r.json()) # this part needs to be modified/adjusted nextPageToken = json_data.get("nextPageToken") with open('myJsonFile.json', 'w') as outfile: json.dump(json_data, outfile, sort_keys=True, indent=4) print("All Done!")
json_data.update(r.json())
Должен сделать свое дело.