【发布时间】:2021-03-02 10:59:09
【问题描述】:
更新:修复:- 只是发现我的 .bashrc 缺少以下内容
您可以使用环境变量更新 bash 配置文件
if [ -f ~/.bash_profile ]; then\
. ~/.bash_profile\
fi
我正在尝试来自 youtube 的 corey schafer 的 API 脚本。我最近将我的文本编辑器从 Sublime 文本更改为 VSCode。
我期望 Sublime 文本的输出如下,
{'kind': 'youtube#channelListResponse', 'etag': '-bp4b5Yy0e-HRWQsadmZk2A75GE', 'pageInfo': {'totalResults': 1, 'resultsPerPage': 5}, 'items': [{'kind': 'youtube#channel', 'etag': 'vakSZODpMKK8i9f3UStrRvd2sQA', 'id': 'UCCezIgC97PvUuR4_gbFUs5g', 'statistics': {'viewCount': '47863717', 'subscriberCount': '667000', 'hiddenSubscriberCount': False, 'videoCount': '230'}}]}
[Finished in 1.0s]
我收到以下错误,请注意我已将 python 别名为 python3 我是初学者。如果我缺少基本的东西,请告诉我
python -u "/Users/natluri/Documents/ytproj/youtubeapi.py"
Traceback (most recent call last):
File "/Users/natluri/Documents/ytproj/youtubeapi.py", line 5, in <module>
youtube = build('youtube', 'v3', developerKey=api_key)
File "/usr/local/lib/python3.9/site-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper
return wrapped(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/googleapiclient/discovery.py", line 278, in build
service = build_from_document(
File "/usr/local/lib/python3.9/site-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper
return wrapped(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/googleapiclient/discovery.py", line 527, in build_from_document
credentials = _auth.default_credentials(
File "/usr/local/lib/python3.9/site-packages/googleapiclient/_auth.py", line 54, in default_credentials
credentials, _ = google.auth.default(scopes=scopes, quota_project_id=quota_project_id)
File "/usr/local/lib/python3.9/site-packages/google/auth/_default.py", line 356, in default
raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https://cloud.google.com/docs/authentication/getting-started
【问题讨论】:
-
您的 google 凭据文件似乎丢失了。
-
无法自动确定凭据。请设置 GOOGLE_APPLICATION_CREDENTIALS 或显式创建凭据并重新运行应用程序。 接缝非常不言自明。
标签: python google-api youtube-api google-api-python-client