我开始考虑将 YouTube API 与 python 一起使用,但文档中给出的示例似乎与快速入门指南不一致。
可以在此处找到快速入门指南,其中建议您从此处的 API 文档中获取一些示例代码,这些代码将从 API请求“YouTube 开发人员”频道的一些信息。现在在快速入门指南中,他们说用您的 API 密钥替换“YOUR_API_KEY”字符串,但正如您从示例代码中看到的那样,它不存在。
# -*- 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 = …Run Code Online (Sandbox Code Playgroud)