I am testing the google drive api V3 files.list method after testing the API on the Google site
Try me I received the expected results.
{
"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..."
}]
}
But when using python I am missing this part:
"kind": "drive#fileList",
"nextPageToken": "~!!~AI9......",
"incompleteSearch": false,
"files":
This is my code:
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))
Result:
[
{
"kind": "drive#file",
"id": "1HL...",
"name": "Slack Channel DLs",
"mimeType": "application/vnd.google-apps.folder",
"teamDriveId": "0AD...",
"driveId": "0AD..."
}]
method 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)
files = results.get('files', [])
returns the files
object of the whole response, which should be in results
on the previous line.
To print the whole response, return results
instead of files
.
Reference:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.