Last active
December 19, 2017 18:14
-
-
Save gmemstr/b80f3e6572ba8df91d8f1ccf6a0b790f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Attempts to harvest as many YouTube video IDs from | |
# a given channel as possible, might not be able to fetch | |
# them all but gives it a pretty good shot | |
# Get your API key from https://console.developers.google.com/ | |
import requests | |
import json | |
key = "GOOGLEAPIS_KEY" | |
channel_id = "UCKab3hYnOoTZZbEUQBMx-ww" | |
url = "https://www.googleapis.com/youtube/v3/search?key="+key+"&channelId="+channel_id+"&part=snippet,id&order=date&maxResults=50" | |
final = [] | |
r = requests.get(url) | |
data = r.json() | |
def iterateData(data): | |
for video in data['items']: | |
if video['id']['kind'] == "youtube#video": | |
print(video['id']['videoId']) | |
try: | |
nextPage(data['nextPageToken']) | |
except: | |
print(data) | |
def nextPage(token): | |
r = requests.get(url + "&pageToken=" + token) | |
data = r.json() | |
iterateData(data) | |
iterateData(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment