Python 3.x “如何制作驱动器文件夹”;“向网络公开”;在Python中使用Google API v3?
我可以使用以下方法创建文件夹:Python 3.x “如何制作驱动器文件夹”;“向网络公开”;在Python中使用Google API v3?,python-3.x,google-drive-api,google-api-python-client,Python 3.x,Google Drive Api,Google Api Python Client,我可以使用以下方法创建文件夹: from Google import Create_Service CLIENT_SECRET_FILE = "credentials_gsuite.json" API_NAME = "drive" API_VERSION ="v3" SCOPES = ["https://www.googleapis.com/auth/drive"] service = Create_Service
from Google import Create_Service
CLIENT_SECRET_FILE = "credentials_gsuite.json"
API_NAME = "drive"
API_VERSION ="v3"
SCOPES = ["https://www.googleapis.com/auth/drive"]
service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES)
folder_name = "Folder"
file_metadata = {"name" : folder_name, "mimeType" : "application/vnd.google-apps.folder"}
service.files().create(body=file_metadata,).execute()
我需要将文件夹“公开给网络”。为此,我需要指定权限:
'role': 'reader
和一种类型,用于:
'type': 'anyone'
并容许:
"allowFileDiscovery": True
从文件来看,这应该是可行的:
from Google import Create_Service
CLIENT_SECRET_FILE = "credentials_gsuite.json"
API_NAME = "drive"
API_VERSION ="v3"
SCOPES = ["https://www.googleapis.com/auth/drive"]
service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES)
folder_name = "Folder"
file_metadata = {"name" : folder_name, "mimeType" : "application/vnd.google-apps.folder", 'role': 'reader', 'type': 'anyone',"allowFileDiscovery": True}
service.files().create(body=file_metadata,).execute()
但我不会把它发布到网上。我错过了什么
文件:
修改点:
- 不幸的是,在
方法中,似乎service.files().create()
是不可写的。当权限
用作“Files:create”的请求主体时,会出现类似{“mimeType”:“application/vnd.google apps.folder”,“name”:“sample”,“permissions”:[{“role”:“reader”,“type”:“any”,“allowFileDiscovery”:true}]}
。因此,在这种情况下,需要在创建新文件夹后使用“权限:创建”方法的错误,资源主体包括不可直接写入的字段。
- 不幸的是,在
方法中,似乎service.files().create()
是不可写的。当权限
用作“Files:create”的请求主体时,会出现类似{“mimeType”:“application/vnd.google apps.folder”,“name”:“sample”,“permissions”:[{“role”:“reader”,“type”:“any”,“allowFileDiscovery”:true}]}
。因此,在这种情况下,需要在创建新文件夹后使用“权限:创建”方法的错误,资源主体包括不可直接写入的字段。
folder_name = "Folder"
file_metadata = {"name": folder_name, "mimeType": "application/vnd.google-apps.folder"}
folder = service.files().create(body=file_metadata,).execute()
folderId = folder.get('id')
permission = {
'role': 'reader',
'type': 'anyone',
'allowFileDiscovery': True
}
res = service.permissions().create(fileId=folderId, body=permission).execute()
print(res)