文件未出现在 Google 驱动器中 - Google 使用 Python 创建的文档
File does not appear in Google Drive - Google docs created with Python
后面显示的代码运行良好。我看到文件正在我的 Jupiter 笔记本中创建,因此该脚本似乎有效。唯一的问题是,该文件没有出现在我的云端硬盘中。
creds_1 = ServiceAccountCredentials.from_json_keyfile_name("creds_1.json", scope)
service = build('docs', 'v1', credentials=creds_1)
title = 'My Document'
body = {
"body": {},
"title": "My document2"
}
doc = service.documents().create(body=body).execute()
print('Created document with title: {0}'.format(doc.get('title')))
这是因为服务帐户有自己的云端硬盘,所以您没有将其上传到您的个人云端硬盘。服务帐户独立于您的用户。
一个选项是在您的云端硬盘中创建一个文件夹,与服务帐户共享,然后让代码将文件上传到那里。
另一种方法,如果您是 G Suite User, would be configuring the Service Account to impersonate your user with Domain Wide Delegation 并将文件直接上传到您的云端硬盘。
后面显示的代码运行良好。我看到文件正在我的 Jupiter 笔记本中创建,因此该脚本似乎有效。唯一的问题是,该文件没有出现在我的云端硬盘中。
creds_1 = ServiceAccountCredentials.from_json_keyfile_name("creds_1.json", scope)
service = build('docs', 'v1', credentials=creds_1)
title = 'My Document'
body = {
"body": {},
"title": "My document2"
}
doc = service.documents().create(body=body).execute()
print('Created document with title: {0}'.format(doc.get('title')))
这是因为服务帐户有自己的云端硬盘,所以您没有将其上传到您的个人云端硬盘。服务帐户独立于您的用户。
一个选项是在您的云端硬盘中创建一个文件夹,与服务帐户共享,然后让代码将文件上传到那里。
另一种方法,如果您是 G Suite User, would be configuring the Service Account to impersonate your user with Domain Wide Delegation 并将文件直接上传到您的云端硬盘。