使用客户端 API 在 Google 云端硬盘应用程序数据文件夹中创建 Google 表格电子表格
Creating a Google Sheets spreadsheet in the Google Drive app data folder with the client-side API
我想使用客户端 JS 在 Google Drive App Data 文件夹(API docs at https://developers.google.com/drive/api/v3/appdata)中创建一个 Google Sheet .
我可以像这样创建非 Sheet 文件(根据 browser quickstart for the Sheets API 处理所有身份验证内容后):
gapi.client.drive.files.create({
resource: {
name: 'myfile.txt',
parents: ['appDataFolder'],
mimeType: 'text/plain'
},
fields: 'id'
}).then(res => {
console.log("Created OK: response was ", res);
}).catch(e => {
console.log("Creation failed: error was ", e)
})
但是,如果我使用 mimeType: 'application/vnd.google-apps.spreadsheet'
然后我得到这个错误:
reason: "notSupportedForAppDataFolderFiles",
message: "Method not supported for files within the Application Data folder."
此错误消息似乎完全没有记录。我的 怀疑 是不允许这样做:您不能将 Google Sheets 存储在 App Data 文件夹中,可能是因为 Sheets 实际上 根本没有作为文件存储在 Drive 中,它们看起来是通过 Drive 团队的某种 UI 伪造。但我没有证实这一点。
我想这样做的原因是请求访问 App Data 文件夹的应用不需要请求访问所有其他文件。如果我无法将 Sheet 放入 App Data 文件夹,那么据我所知,为了创建电子表格,我的应用程序需要请求对 all 用户的电子表格,它完全不需要;它会使用自己的,仅此而已。我不想请求该访问权限,因为用户会(正确地)将其视为过度扩张。
The application data folder is automatically created when you attempt to create a file in it.
Use this folder to store any files that the user shouldn't directly interact with.
This folder is only accessible by your application and its contents are hidden from the user and from other Drive apps.
因此,虽然没有关于 Google 表格不允许出现在应用程序数据文件夹中的直接信息,但可以假设 Google 表格文件不符合上述条件。
至于范围:
- 您可以使用范围
https://www.googleapis.com/auth/drive.file
。
- 这是一个狭窄的范围,使应用程序只能访问此应用程序创建的文件,请参阅 here
- 通过使用此范围,您可以避免请求访问所有用户文件,因此用户无需担心向应用程序提供此范围。
我想使用客户端 JS 在 Google Drive App Data 文件夹(API docs at https://developers.google.com/drive/api/v3/appdata)中创建一个 Google Sheet .
我可以像这样创建非 Sheet 文件(根据 browser quickstart for the Sheets API 处理所有身份验证内容后):
gapi.client.drive.files.create({
resource: {
name: 'myfile.txt',
parents: ['appDataFolder'],
mimeType: 'text/plain'
},
fields: 'id'
}).then(res => {
console.log("Created OK: response was ", res);
}).catch(e => {
console.log("Creation failed: error was ", e)
})
但是,如果我使用 mimeType: 'application/vnd.google-apps.spreadsheet'
然后我得到这个错误:
reason: "notSupportedForAppDataFolderFiles",
message: "Method not supported for files within the Application Data folder."
此错误消息似乎完全没有记录。我的 怀疑 是不允许这样做:您不能将 Google Sheets 存储在 App Data 文件夹中,可能是因为 Sheets 实际上 根本没有作为文件存储在 Drive 中,它们看起来是通过 Drive 团队的某种 UI 伪造。但我没有证实这一点。
我想这样做的原因是请求访问 App Data 文件夹的应用不需要请求访问所有其他文件。如果我无法将 Sheet 放入 App Data 文件夹,那么据我所知,为了创建电子表格,我的应用程序需要请求对 all 用户的电子表格,它完全不需要;它会使用自己的,仅此而已。我不想请求该访问权限,因为用户会(正确地)将其视为过度扩张。
The application data folder is automatically created when you attempt to create a file in it.
Use this folder to store any files that the user shouldn't directly interact with.
This folder is only accessible by your application and its contents are hidden from the user and from other Drive apps.
因此,虽然没有关于 Google 表格不允许出现在应用程序数据文件夹中的直接信息,但可以假设 Google 表格文件不符合上述条件。
至于范围:
- 您可以使用范围
https://www.googleapis.com/auth/drive.file
。 - 这是一个狭窄的范围,使应用程序只能访问此应用程序创建的文件,请参阅 here
- 通过使用此范围,您可以避免请求访问所有用户文件,因此用户无需担心向应用程序提供此范围。