【发布时间】:2021-07-14 21:07:11
【问题描述】:
我正在尝试使用 Python 中的 YouTube v3 API 并根据代码中的要求在 YouTube 上搜索视频,但出现此错误。
如何防止这种情况发生?这段代码也来自谷歌。您可以在 Google 网站here 上编辑代码。我在这方面完全是菜鸟,所以如果你有任何我将来必须知道的信息,请说出来。谢谢
# -*- coding: utf-8 -*-
# Sample Python code for youtube.search.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.force-ssl"]
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 = "client_secret.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 = api.youtube.search().list(
part="snippet",
location="United States",
maxResults=5,
order="date",
q="programming",
regionCode="US",
relevanceLanguage="en",
safeSearch="none",
videoDimension="any",
videoDuration="any"
)
response = request.execute()
print(response)
if __name__ == "__main__":
main()
第二个错误
【问题讨论】:
标签: python python-3.x google-api youtube-data-api google-api-python-client