Skip to content Skip to sidebar Skip to footer

I Can't Access A Shared File That Is In A Google Shared Drive

I am using Python to list out files shared with my google service account. The process is working fine except that one file that I know is shared with my service account is not com

Solution 1:

In order to access the files on a shared Drive, you must specify the Drive ID in the files: list method using the a driveId=XXXXXXXXXXXXXXXXXX parameter.

You can first obtain this by using the Drives: list method provided by the Google Drive REST API as you can see here.

You can get a list of the files on a specific shared drive with the following code:

defgetSharedDriveFiles(service):

    service = create_directory_service("Service_Account_Email")

    results = service.drives().list().execute()
    items = results.get('drives', [])

    driveIDs = []

    ifnot items:
        print('No files found')
    else:
        print('Drives:')
        for item in items:
            print(u'{0} ({1})'.format(item['name'], item['id']))
            driveIDs.append(item['id'])

    results = service.files().list(pageSize = 10, fields='nextPageToken, files(name, id)', driveId='SHARED_DRIVE_ID', corpora='drive', includeItemsFromAllDrives=True, supportsAllDrives=True).execute()

    items = results.get('files', [])
    ifnot items:
        print('No files found')
    else:
        print('Files:')
        for item in items:
            print(u'{0} ({1})'.format(item['name'], item['id']))

I made sure that my service account's email was added to the list of users the Drive is shared with and I was able to get an output of all the files in the Drive regardless of which domain the owner of the file is a member of.

Post a Comment for "I Can't Access A Shared File That Is In A Google Shared Drive"