Skip to content

Instantly share code, notes, and snippets.

@gmemstr
Last active December 19, 2017 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmemstr/b80f3e6572ba8df91d8f1ccf6a0b790f to your computer and use it in GitHub Desktop.
Save gmemstr/b80f3e6572ba8df91d8f1ccf6a0b790f to your computer and use it in GitHub Desktop.
# 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