Fetch Data of a YouTube Video using Google API | Python


import os
import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors

scopes = ["https://www.googleapis.com/auth/youtube.force-ssl"]

def main():
    api_service_name = "youtube"
    api_version = "v3"
    client_secrets_file = "client_secret.json"

    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, credentials=credentials)

    part_string = 'contentDetails,statistics,snippet'
    videoid = "Your Video ID"
    response = youtube.videos().list(part=part_string,id=videoid).execute()
    print(response)

if __name__ == "__main__":
    main()

Post a Comment

Previous Post Next Post