-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyoutubeAPI.py
More file actions
44 lines (36 loc) · 1.42 KB
/
youtubeAPI.py
File metadata and controls
44 lines (36 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'''
https://www.googleapis.com/youtube/v3/videos?part=statistics&id=GVGmKoQ_MPI&key=AIzaSyAPqvy4xQqjkaTZZIGwMppQ9S5D3UKBK4E
'''
# -*- coding: utf-8 -*-
# Sample Python code for youtube.videos.list
# See instructions for running these code samples locally:
# https://developers.google.com/explorer-help/guides/code_samples#python
import os
import json
import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors
scopes = ["https://www.googleapis.com/auth/youtube.readonly"]
def main():
# Disable OAuthlib's HTTPS verification when running locally.
# *DO NOT* leave this option enabled in production.
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
api_service_name = "youtube"
api_version = "v3"
client_secrets_file = "YOUR_CLIENT_SECRET_FILE.json"
# Get credentials and create an API client
# flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
# client_secrets_file, scopes)
# credentials = flow.run_console()
youtube = googleapiclient.discovery.build(
api_service_name, api_version, developerKey="AIzaSyAPqvy4xQqjkaTZZIGwMppQ9S5D3UKBK4E")
request = youtube.videos().list(
part="snippet,contentDetails,statistics",
id="GVGmKoQ_MPI"
)
response = request.execute()
print(response)
views = response['items'][0]['statistics']['viewCount']
print(views)
if __name__ == "__main__":
main()