reading excel sheet in google drive folder

42 views Asked by At

I am trying to read excel sheet in google drive and output as pandas dataframe. here is what I have, but when i print "excel_files", its empty. I am not sure why, it made connection ok, and i have the right folder ID. Any help is appreciated. thanks!

import pickle
import os.path
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build

# If modifying these SCOPES, delete the file token.pickle.
SCOPES = ['https://www.googleapis.com/auth/drive.readonly']

creds = None
if os.path.exists('token.pickle'):
    with open('token.pickle', 'rb') as token:
        creds = pickle.load(token)

if not creds or not creds.valid:
    flow = InstalledAppFlow.from_client_secrets_file(
        'credentials.json', SCOPES)
    creds = flow.run_local_server(port=0)

    with open('token.pickle', 'wb') as token:
        pickle.dump(creds, token)

service = build('drive', 'v3', credentials=creds)

folder_id = 'YOUR_FOLDER_ID'
results = service.files().list(q=f"'{folder_id}' in parents and mimeType='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'",
                               fields="files(id, name)").execute()

excel_files = results.get('files', []) # returns empty, even though there is no error in connection
0

There are 0 answers