E
E
Evgeny .2018-07-22 21:13:55
Python
Evgeny ., 2018-07-22 21:13:55

Google api: how to attach a file from google-drive to a letter?

There are no problems with sending a letter via gmail with attachments, or downloading a file from drive.
but how to attach a file located in google-drive to a letter - I didn’t find it in the docks, maybe someone came across it.
for earlier big senks :)
(Python language, Oauth2 authorization.)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ivanov, 2018-08-14
@oshliaer

Just add a link to the file.

from __future__ import print_function
from googleapiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
from qs import CreateMessage, SendMessage

SCOPES = 'https://www.googleapis.com/auth/gmail.send'

def main():
    """Shows basic usage of the Gmail API.
    Lists the user's Gmail labels.
    """
    store = file.Storage('token.json')
    creds = store.get()
    if not creds or creds.invalid:
        flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
        creds = tools.run_flow(flow, store)
    service = build('gmail', 'v1', http=creds.authorize(Http()))

    message = CreateMessage('[email protected]',
                            '[email protected]',
                            'test',
                            'https://docs.google.com/spreadsheets/d/xxx/edit?usp=sharing')
    SendMessage(service, 'me', message=message)

if __name__ == '__main__':
    main()

Most likely there is an option that will share the files for everyone, if necessary.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question