2016-12-20 21 views
0

我使用pyDrive將文件上傳到我的Google雲端硬盤。我可以將文件上傳到任何特定的文件夾。如何向筆記本發送上傳文件到Google Drive的收件人?

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() 

如何與其他人共享上傳的文件並使用pyDrive或官方Google Drive REST API向收件人發送便條?

+1

我相信這是你要找的東西:https://developers.google.com/drive/v3/web/manage-sharing它也有在python中設置權限的代碼 –

回答

1

這是在pydrive通過InsertPermission

創建用戶或組電子郵件地址的權限默認情況下會向該用戶或組發送共享電子郵件。

有關更多信息,請參閱creating permissions上的Drive API文檔。

0

這可以使用Handling special metadata,更具體地說:InsertPermission來完成。

可以共享一個用戶(使用他們的電子郵件地址)的文件,像這樣:

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


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

更換readerwriter,如果你想給用戶寫權限。

InsertPermission接受官方API docs中描述的所有標誌。

注意:PyDrive使用Google Drive API的v2

相關問題