I am getting started looking at using the YouTube API with python yet the examples given in the documentation seem to disagree with the quickstart guide.
The quickstart guide can be found here and in it they recommend you grab some sample code from the API documentation here that will request from the API some information for the "YouTube Developers" channel. Now in the quickstart guide, they say to replace the "YOUR_API_KEY" string with your API key but as you can see from the sample code it is not there.
# -*- coding: utf-8 -*-
# Sample Python code for youtube.channels.list
# See instructions for running these code samples locally:
# https://developers.google.com/explorer-help/guides/code_samples#python
import os
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, credentials=credentials)
request = youtube.channels().list(
part="snippet,contentDetails,statistics",
id="UC_x5XG1OV2P6uZZ5FSM9Ttw"
)
response = request.execute()
print(response)
if __name__ == "__main__":
main()
The "YOUR_CLIENT_SECRET_FILE" string i believe is only for requests that require user authentication, which should not be the case with this type of request.
So where are you supposed to supply the API key? Is the guide out of date?
All help is much appreciated!