Add shared Google Drive folder support (#2562)

closes #1634

Adds support for loading files from a shared Google Drive folder to
`GoogleDriveLoader`. Shared drives are commonly used by businesses on
their Google Workspace accounts (this is my particular use case).
This commit is contained in:
Will Henchy 2023-04-08 11:46:55 -04:00 committed by GitHub
parent 7bf5b0ccd3
commit 125afb51d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -148,7 +148,7 @@ class GoogleDriveLoader(BaseLoader, BaseModel):
creds = self._load_credentials() creds = self._load_credentials()
service = build("drive", "v3", credentials=creds) service = build("drive", "v3", credentials=creds)
file = service.files().get(fileId=id).execute() file = service.files().get(fileId=id, supportsAllDrives=True).execute()
request = service.files().export_media(fileId=id, mimeType="text/plain") request = service.files().export_media(fileId=id, mimeType="text/plain")
fh = BytesIO() fh = BytesIO()
downloader = MediaIoBaseDownload(fh, request) downloader = MediaIoBaseDownload(fh, request)
@ -182,6 +182,8 @@ class GoogleDriveLoader(BaseLoader, BaseModel):
.list( .list(
q=f"'{self.folder_id}' in parents", q=f"'{self.folder_id}' in parents",
pageSize=1000, pageSize=1000,
includeItemsFromAllDrives=True,
supportsAllDrives=True,
fields="nextPageToken, files(id, name, mimeType)", fields="nextPageToken, files(id, name, mimeType)",
) )
.execute() .execute()
@ -217,7 +219,7 @@ class GoogleDriveLoader(BaseLoader, BaseModel):
creds = self._load_credentials() creds = self._load_credentials()
service = build("drive", "v3", credentials=creds) service = build("drive", "v3", credentials=creds)
file = service.files().get(fileId=id).execute() file = service.files().get(fileId=id, supportsAllDrives=True).execute()
request = service.files().get_media(fileId=id) request = service.files().get_media(fileId=id)
fh = BytesIO() fh = BytesIO()
downloader = MediaIoBaseDownload(fh, request) downloader = MediaIoBaseDownload(fh, request)