I don't seem to find many articles on this. The tutorial from Google only shows creating folders in a regular Google Drive folder.
Below is my function and it fails with oogleapiclient.errors.HttpError: <HttpError 404 when requesting https://www.googleapis.com/drive/v3/files?alt=json returned "File not found: myteamdrivefolderid.". Details: "File not found: myteamdrivefolderid.">
oogleapiclient.errors.HttpError: <HttpError 404 when requesting https://www.googleapis.com/drive/v3/files?alt=json returned "File not found: myteamdrivefolderid.". Details: "File not found: myteamdrivefolderid.">
My app is a Python desktop app and has already been authorized to have full Drive read/write scope.
def create_folder(service, name, parent_id=None, **kwargs):
# Create a folder on Drive, returns the newely created folders ID
body = {
'name': name,
'mimeType': "application/vnd.google-apps.folder"
}
if parent_id:
body['parents'] = [parent_id]
if 'teamDriveId' in kwargs:
body['teamDriveId'] = kwargs['teamDriveId']
folder = service.files().create(body=body).execute()
return folder['id']
I believe your goal and situation as follows.
supportsAllDrives
to the query parameter.teamDriveId
is deprecated. Please use driveId
. Ref When above points are reflected to your script, it becomes as follows.
body = {
'name': name,
'mimeType': "application/vnd.google-apps.folder"
}
if parent_id:
body['parents'] = [parent_id]
if 'teamDriveId' in kwargs:
body['driveId'] = kwargs['teamDriveId'] # Modified
folder = service.files().create(body=body, supportsAllDrives=True).execute() # Modified
return folder['id']
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.