I have a Google Drive folder to which customers are uploading files. Some of them are actual GDrive files, and some are shortcuts to files on other drives or folders to which I have permission to read. I can successfully get
the files using the Python Library. However, for the shortcut files I get a target id - but trying to get
that ID ends up in a 404 error, even though I have permissions to access it on a web browser.
When I crawl my drive and use:
results = service.files().list(
pageSize=10, fields="nextPageToken, files(id, name)").execute()
items = results.get('files', [])
I get my entire drive, meaning every metadata about any file and folder there is on my drive. Some of theme are MimeType: 'application/vnd.google-apps.shortcut'. Those files have an addition field called: 'shortcutDetails'. It's look like this:
'shortcutDetails': {'targetId': SOME_ID, 'targetMimeType': SOME_MIMETYPE}
The targetId is supposed to point to the original file, but when I'm trying to get that file I get a bed request 404 file not find, I suppose because it's not in my drive. I am using this function:
def resolve_shortcut(service, target_id):
logging.info(f"Resolving shortcut with target: {target_id}")
results = service.files().get(fileId=target_id, fields="files(*)", supportsAllDrives=True).execute()
raw_files = results.get("files", [])
logging.info(f"Shortcut resolved, first result id: {raw_files[0]['id']}...")
assert len(raw_files) == 1
return raw_files[0]
And I get in return:
<HttpError 404 when requesting
https://www.googleapis.com/drive/v3/files/SOME_ID?fields=files%28%2A%29&supportsAllDrives=true&alt=json
returned "File not found:
SOME_ID.". Details: "[{'domain':
'global', 'reason': 'notFound', 'message': 'File not found:
SOME_ID.', 'locationType':
'parameter', 'location': 'fileId'}]">
It there is any way to fetch the original file?? Thanks!