【发布时间】:2021-04-09 19:22:51
【问题描述】:
我在 Google 网站上测试 API 后正在测试 google drive api V3 files.list 方法
Try me我收到了预期的结果。
{
"kind": "drive#fileList",
"nextPageToken": "~!!~AI9......",
"incompleteSearch": false,
"files": [
{
"kind": "drive#file",
"id": "1HL...",
"name": "Slack Channel DLs",
"mimeType": "application/vnd.google-apps.folder",
"teamDriveId": "0AD...",
"driveId": "0AD..."
}]
}
但是在使用 python 时,我缺少这部分:
"kind": "drive#fileList",
"nextPageToken": "~!!~AI9......",
"incompleteSearch": false,
"files":
这是我的代码:
import json
from main_methods import GdriveConnection
# mainmethods is a script for my methods.
googleDrive = GdriveConnection()
files = googleDrive.listFiles()
print(json.dumps(files, indent=2))
count = 0
for file in files:
count = count + 1
print('\n Total files: ' + str(count))
结果:
[
{
"kind": "drive#file",
"id": "1HL...",
"name": "Slack Channel DLs",
"mimeType": "application/vnd.google-apps.folder",
"teamDriveId": "0AD...",
"driveId": "0AD..."
}]
方法 GdriveConnection()
def listFiles(self):
service = build('drive', 'v3', credentials=self.creds)
results = service.files().list(corpora='user', includeItemsFromAllDrives='true', orderBy='folder', pageSize='1000', supportsAllDrives='true', supportsTeamDrives='true').execute()
files = results.get('files', [])
return(files)
【问题讨论】:
标签: python google-api google-drive-api