1

I am with pyDrive to upload files to my Google Drive. I am able to upload files to any specific folder.

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

gauth = GoogleAuth()
gauth.LocalWebserverAuth()

drive = GoogleDrive(gauth)

file1 = drive.CreateFile({'title': 'myfile.txt', 'parents': [{"kind": "drive#fileLink","id": {FOLDER_ID}}]})
file1.SetContentFile('myfile.txt')
file1.Upload()

How can I share the uploaded file with other people and send a note to the recipients either using pyDrive or official Google Drive REST API?

alextc
  • 3,206
  • 10
  • 63
  • 107
  • 1
    I believe this is what yo are looking for: https://developers.google.com/drive/v3/web/manage-sharing It has code for permissions setting in python as well – Remya CV Dec 20 '16 at 06:22

2 Answers2

2

This is available in pydrive via InsertPermission.

The act of creating a permission for a user or group email address will by default send a sharing email to that user or group.

See the Drive API documentation on creating permissions for more info.

Peter
  • 5,501
  • 2
  • 26
  • 42
0

This can be done using Handling special metadata, more specifically: InsertPermission.

You can share a document with a user (using their email address) like so:

# Add a read permission for the user with the specified email address.
permission = file1.InsertPermission({
                        'type': 'user',
                        'value': '<email@address.here>',
                        'role': 'reader'})


# You can check which permission settings a file has:
print(file1['permissions'])

Replace reader with writer if you want give the user write permission.

InsertPermission accepts all flags described in the official API docs.

Note: PyDrive uses v2 of the Google Drive API.

Robin Nabel
  • 2,170
  • 1
  • 21
  • 26