Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get file's links with google-drive-api python

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')
like image 382
Ivan Telnov Avatar asked Aug 30 '16 14:08

Ivan Telnov


People also ask

How do I get files from Google Drive API?

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.


1 Answers

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')
like image 162
Ivan Telnov Avatar answered Sep 17 '22 16:09

Ivan Telnov