Skip to content

Instantly share code, notes, and snippets.

@eggman
Created April 9, 2020 21:00
Show Gist options
  • Save eggman/7fc71b6984cc437a959ab5b4ebe8627d to your computer and use it in GitHub Desktop.
Save eggman/7fc71b6984cc437a959ab5b4ebe8627d to your computer and use it in GitHub Desktop.

Get YouTube video info

  • python3

prepare

$ pip3 install google-python-api-client pprint
$ copy > config.json
{ "api_key" : "your api key" }
# -*- coding: utf-8 -*-
import os
import googleapiclient.discovery
import googleapiclient.errors
import json
import pprint
scopes = ["https://www.googleapis.com/auth/youtube.readonly"]
def main():
api_service_name = "youtube"
api_version = "v3"
json_open = open('config.json', 'r')
json_load = json.load(json_open)
api_key = json_load['api_key']
videoIds = json_load['videoId']
youtube = googleapiclient.discovery.build(
api_service_name, api_version, developerKey=api_key)
request = youtube.videos().list(
part="snippet,contentDetails,status,statistics,player,topicDetails",
id=videoIds,
)
response = request.execute()
pprint.pprint(response)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment