I've worked with Google Drive
Api
some time and I can't find the way to get the link for file's view on Drive pragramatically.
There is function
which creates folder and returns its id, however additionally I need to return a link
for view
only.
Thank you!
def create_folder(folder_name='no_name', parent_id=''):
data = {'name': folder_name,
'mimeType': 'application/vnd.google-apps.folder',
'parents': [parent_id],
}
new = DRIVE.files().create(body=data, fields='id').execute()
return new.get('id')
folder = create_folder('some_name', 'some_parent_id')
If you provide the URL parameter alt=media , then the response includes the file contents in the response body. Downloading content with alt=media only works if the file is stored in Drive. To download Google Docs, Sheets, and Slides use files. export instead.
So, create folder and return a View link is possible by adding "webViewLink" to fields in method files().create(). The function will be the next:
def create_folder(parent_id, folder_name='no_name', ):
data = {'name': folder_name,
'mimeType': 'application/vnd.google-apps.folder',
'parents': ['{0}'.format(parent_id)],
}
new = DRIVE.files().create(body=data, fields='webViewLink, id').execute()
return new.get('webViewLink')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With