- python3
$ 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() |