【发布时间】:2023-03-27 09:21:01
【问题描述】:
输出仅显示我拥有的我与他人共享的谷歌文档,而不是我共享的那些。 如何查看共享给我的文件夹结构和文件?
我正在使用我的公司 Gmail 帐户。使用了 Google 服务帐号。
代码如下。
from __future__ import print_function
import pickle
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
# https://developers.google.com/analytics/devguides/config/mgmt/v3/quickstart/service-py
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name('creds.json' % path, scope)
# https://developers.google.com/drive/api/v3/quickstart/python
service = build('drive', 'v3', credentials=credentials)
# Call the Drive v3 API
results = service.files().list(
pageSize=10, fields="nextPageToken, files(id, name)").execute()
items = results.get('files', [])
if not items:
print('No files found.')
else:
print('Files:')
for item in items:
print(u'{0} ({1})'.format(item['name'], item['id']))
【问题讨论】:
-
如果服务账号的邮箱不与文件夹共享,当你将服务账号的邮箱共享到文件夹时,会得到什么结果?
-
解决了。文件夹未与服务帐户共享
-
感谢您的回复。我很高兴你的问题得到了解决。当您的问题解决后,您可以将其发布为答案吗?这样,它对其他有相同问题的用户也很有用。
-
@Tanaike,这意味着应该将电子邮件(来自服务帐户)添加为 Google Drive 文件夹中的查看者(或编辑者——根据需要)
标签: python google-api-python-client