0
votes

I would like to create a Google Sheet in the Google Drive App Data folder (API docs at https://developers.google.com/drive/api/v3/appdata) using client side JS.

I can create non-Sheet files like this (after handling all the authentication stuff, as per the 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)
})

However, if I use mimeType: 'application/vnd.google-apps.spreadsheet' then I get this error back:

reason: "notSupportedForAppDataFolderFiles",
message: "Method not supported for files within the Application Data folder."

This error message seems to be entirely undocumented. My suspicion is that this is just not allowed: you can't store Google Sheets in the App Data folder, probably because Sheets aren't really stored as files in Drive at all and they appear so through some sort of UI fakeout by the Drive team. But I have no confirmation of this.

The reason I'd like to do this is that an app which requests access to the App Data folder does not need to request access to all other files. If I can't put a Sheet in the App Data folder, then as far as I'm aware, in order to create a spreadsheet my app will need to request complete access to all the user's spreadsheets, which it completely does not need; it will use its own one and that's it. I don't want to ask for that access because users will (correctly) see that as massive overreach.

1

1 Answers

1
votes

The documentation specifies:

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.

So while there is no direct information about Google sheets not being allowed in the application data folder, one can assume that a Google Sheets file does not meet the mentioned criteria.

As for scopes:

  • You can use the scope https://www.googleapis.com/auth/drive.file.
  • This is a narrow scope that gives the application only access to files that have been created by this application, see here
  • By using this scope, you avoid asking for access to all users files, and thus the users do not need to worry about providing this scopes to the application.