我正在尝试在Google Cloud函数中创建Blogger API服务对象。我引用https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application中的示例(“在Compute Engine,Kubernetes Engine,App Engine flexible环境和Cloud Functions上获取凭据”一节)
给出的示例适用于Google Starage。我正在尝试将其转换为Blogger API的Google API客户端。我找不到有关如何使用此默认凭据创建Blogger API服务对象的文档。我尝试重用
中的代码我尝试了以下代码,但出现错误。我知道这是错误的,但是我没有关于如何使用此证书的文档。
from google.auth import compute_engine
import googleapiclient.discovery
credentials = compute_engine.Credentials()
print(type(credentials))
blogger = googleapiclient.discovery.build('blogger', 'v3', credentials=credentials)
print(blogger)
我收到以下错误:
E 2020-01-01T20:16:08.656Z TestHTTPFunction h8log1bk5kam Traceback (most recent call last): TestHTTPFunction h8log1bk5kam
E 2020-01-01T20:16:08.656Z TestHTTPFunction h8log1bk5kam File "/env/local/lib/python3.7/site-packages/googleapiclient/discovery_cache/file_cache.py", line 33, in <module> TestHTTPFunction h8log1bk5kam
E 2020-01-01T20:16:08.656Z TestHTTPFunction h8log1bk5kam from oauth2client.contrib.locked_file import LockedFile TestHTTPFunction h8log1bk5kam
E 2020-01-01T20:16:08.656Z TestHTTPFunction h8log1bk5kam ModuleNotFoundError: No module named 'oauth2client' TestHTTPFunction h8log1bk5kam
E 2020-01-01T20:16:08.656Z TestHTTPFunction h8log1bk5kam TestHTTPFunction h8log1bk5kam
E 2020-01-01T20:16:08.656Z TestHTTPFunction h8log1bk5kam During handling of the above exception, another exception occurred: TestHTTPFunction h8log1bk5kam
E 2020-01-01T20:16:08.656Z TestHTTPFunction h8log1bk5kam TestHTTPFunction h8log1bk5kam
E 2020-01-01T20:16:08.656Z TestHTTPFunction h8log1bk5kam Traceback (most recent call last): TestHTTPFunction h8log1bk5kam
E 2020-01-01T20:16:08.656Z TestHTTPFunction h8log1bk5kam File "/env/local/lib/python3.7/site-packages/googleapiclient/discovery_cache/file_cache.py", line 37, in <module> TestHTTPFunction h8log1bk5kam
E 2020-01-01T20:16:08.656Z TestHTTPFunction h8log1bk5kam from oauth2client.locked_file import LockedFile TestHTTPFunction h8log1bk5kam
E 2020-01-01T20:16:08.656Z TestHTTPFunction h8log1bk5kam ModuleNotFoundError: No module named 'oauth2client' TestHTTPFunction h8log1bk5kam
E 2020-01-01T20:16:08.656Z TestHTTPFunction h8log1bk5kam TestHTTPFunction h8log1bk5kam
E 2020-01-01T20:16:08.656Z TestHTTPFunction h8log1bk5kam During handling of the above exception, another exception occurred: TestHTTPFunction h8log1bk5kam
E 2020-01-01T20:16:08.656Z TestHTTPFunction h8log1bk5kam TestHTTPFunction h8log1bk5kam
E 2020-01-01T20:16:08.656Z TestHTTPFunction h8log1bk5kam Traceback (most recent call last): TestHTTPFunction h8log1bk5kam
E 2020-01-01T20:16:08.656Z TestHTTPFunction h8log1bk5kam File "/env/local/lib/python3.7/site-packages/googleapiclient/discovery_cache/__init__.py", line 41, in autodetect TestHTTPFunction h8log1bk5kam
E 2020-01-01T20:16:08.656Z TestHTTPFunction h8log1bk5kam from . import file_cache TestHTTPFunction h8log1bk5kam
E 2020-01-01T20:16:08.656Z TestHTTPFunction h8log1bk5kam File "/env/local/lib/python3.7/site-packages/googleapiclient/discovery_cache/file_cache.py", line 41, in <module> TestHTTPFunction h8log1bk5kam
E 2020-01-01T20:16:08.656Z TestHTTPFunction h8log1bk5kam 'file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth') TestHTTPFunction h8log1bk5kam
E 2020-01-01T20:16:08.656Z TestHTTPFunction h8log1bk5kam ImportError: file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth TestHTTPFunction h8log1bk5kam
I 2020-01-01T20:16:08.656Z TestHTTPFunction h8log1bk5kam URL being requested: GET https://www.googleapis.com/discovery/v1/apis/blogger/v3/rest TestHTTPFunction h8log1bk5kam
I 2020-01-01T20:16:08.723Z TestHTTPFunction h8log1bk5kam <googleapiclient.discovery.Resource object at 0x7ec9066c9710> TestHTTPFunction h8log1bk5kam
I 2020-01-01T20:16:08.724Z TestHTTPFunction h8log1bk5kam URL being requested: GET https://www.googleapis.com/blogger/v3/blogs/2709229652340798222?maxPosts=2&alt=json TestHTTPFunction h8log1bk5kam
E 2020-01-01T20:16:08.752Z TestHTTPFunction h8log1bk5kam Encountered 403 Forbidden with reason "insufficientPermissions" TestHTTPFunction h8log1bk5kam