【发布时间】:2021-09-24 09:56:03
【问题描述】:
这是我的代码(基本相同):
import os
import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors
import json
scopes = ["https://www.googleapis.com/auth/youtube.readonly"]
def main():
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
api_service_name = "youtube"
api_version = "v3"
client_secrets_file = "client_secrets_file.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)
request = youtube.videos().list(
part="statistics",
id="dQw4w9WgXcQ"
)
response = request.execute()
print(response)
if __name__ == "__main__":
main()
这是准确的错误:
Traceback (most recent call last):
File "C:\Users\m8\Desktop\ffs\cockclcosks.py", line 37, in <module>
main()
File "C:\Users\m8\Desktop\ffs\cockclcosks.py", line 22, in main
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
File "C:\Users\m8\anaconda3\lib\site-packages\google_auth_oauthlib\flow.py", line 203, in from_client_secrets_file
with open(client_secrets_file, "r" ) as json_file:
FileNotFoundError: [Errno 2] No such file or directory: 'client_secrets_file.json'
这里是流.py:
199
Returns:
Flow: The constructed Flow instance.
"""
with open(client_secrets_file, "r" ) as json_file:
client_config = json.load(json_file)
return cls.from_client_config(client_config, scopes=scopes, **kwargs)
208
有什么想法吗?我是一个初学者,所以这可能是我不知道的相当愚蠢的事情
所以如果有人知道问题出在哪里,我会在你的额头上一个大大的吻
【问题讨论】:
-
没有这样的文件或目录 - 它正在尝试加载提到的文件。文件是否存在?
标签: python api youtube youtube-data-api