Trevor Buckner
Trevor Buckner

Reputation: 648

Google Drive API get AppProperties with API Key

Question:

Is it possible to access the appProperties field in a Google Drive document via an unauthenticated user (i.e., via API Key or other method rather than Oauth)?

Background:

I have an app that works as a live document editor. It authenticates users via OAuth and allows them to save those documents to their google drive, and later re-open them in my app (google file ids are saved in my database and will load the document text into my app). Create()-ing and Get()-ing these files works fine as long as the user is signed in, and I have the "appProperties" field storing a couple of additional key metadata items.

As a next step, I would like to allow users to mark a document as "public view", and provide read-only access to their file, even for non-logged-in users. In my head, the flow would work as follows:

  1. User_A authenticates with OAuth and creates a document, saved to their google drive.
  2. User_A presses a button in my app, which sets the google document to a public sharing mode?
  3. App generates a "viewer" link that User_A can share with his friends.
  4. User_B does not have a Google account, but visits the "viewer link", and my app looks up the appropriate google document (using API key? since User_B is not logged in)
  5. Document is loaded into my app for viewing.

This seems to mostly work; I can read the file metadata just fine using the API key, and even get the file contents. Side Note: Why do we need the API Key at all, given the quote on the google drive api page: "Note: Authorization optional."

However, the "appProperties" field always returns empty when using the API key!

Edit: After further searching I am just more confused. The closest answer I could find was from this related question here on stackoverflow:

It's very simple. appPropperties is a private field and is available only to the application that added it.

Based on this, it seems Google Drive is treating requests from my app API Key and requests from OAuth users on my app as two separate apps?

Further, I would eventually like to allow users to collaborate on a single document, owned by one user. So instead of just providing a read-only "view" link, they could generate an "editor invitation" link that would allow an authenticated user (User_B gets a google account now) to be added as an authorized collaborator (but not simultaneous editing) on the original (User_A's) document. Is that even possible?

Note I am using the Node.js google api.

Upvotes: 1

Views: 335

Answers (1)

Iamblichus
Iamblichus

Reputation: 19319

This might be a bug:

appProperties are app-specific properties attached to a file. Any call from this app should be able to access them. Therefore, I think calls from this app using an API key should be able to retrieve these properties.

I could reproduce this behaviour: appProperties are populated when using OAuth, but not when using an API key, even though both are created from the same GCP project.

I filed a bug:

After researching this issue, I think this might be a bug. Therefore, I decided to file a bug on Issue Tracker:

To anyone affected by this, I'd suggest to click the top-left star in order to keep track of this and to help prioritizing it.

Reference:

Upvotes: 1

Related Questions