1

I have a GCP project and there is a Jupiter notebook which is to read files from G Drive.

def search_file(request = None):
    try:
        service = build('drive', 'v3', credentials=creds)

        # Call the Drive v3 API
        results = service.files().list(
            pageSize=1, fields="nextPageToken, files(id, name)").execute()
        items = results.get('files', [])

        if not items:
            print('No files found.')
            return
        print('Files:')
        for item in items:
            print(u'{0} ({1})'.format(item['name'], item['id']))
    except HttpError as error:
        print(f'An error occurred: {error}')

I'm using Google's quickstart to retrieve files from G Drive. The authentication and all works fine and the intended drive has just one file on it. But when I execute this search_file method, I'm getting No Files found. message. I'm trying to read one csv file which resides in G Drive. What I have missed or any other alternatives for this?

codebot
  • 2,540
  • 3
  • 38
  • 89

1 Answers1

0

Can you try running the query in the following format?

shared_drive_id = "" # you need to specify specific id of drive folder provided in url of that folder such as https://drive.google.com/drive/folders/<shared_drive_id>
  
query_file = "mimeType='application/vnd.google-apps.document' and trashed=false"
search_file = drive_service.files().list(q=query_file,
                                               fields='files(id)',
                                               driveId=shared_drive_id,
                                               supportsAllDrives=True,
                                               includeItemsFromAllDrives=True,
                                               corpora='drive').execute()
files = search_file.get('files', [])