Mk-Etlinger
Mk-Etlinger

Reputation: 174

googleapis "appProperties" field not being returned for files in node

I'm trying to get the appProperties field to be returned with my files on gdrive, but currently unable to get it working.

"googleapis": "^29.0.0"

Here's my scopes and fields:

scopes: [
    "https://www.googleapis.com/auth/drive",
    "https://www.googleapis.com/auth/drive.file",
    "https://www.googleapis.com/auth/drive.metadata.readonly"
  ]

fields = ["id", "name", "mimeType", "parents", "description", "modifiedTime", "appProperties"]

All of the other properties come back using drive.files.list without issue, but it won't return the appProperties field.

 getFilesByQuery: function( queryString , extraFields ){

    var fields = ["id", "name", "mimeType", "parents", "description", "modifiedTime", "appProperties"];
    if( extraFields && extraFields.length )
      fields = fields.concat( extraFields );

    return drive.files.list({
      'pageSize': 200,
      'fields': `nextPageToken, files(${ fields.join(', ') })`,
      'q': queryString
    });
  }

When I query directly through files/get on dev.google API, this is what I get back for that file:

{
 "name": "US",
 "appProperties": {
  "order": "1"
 }
}

Any ideas?

Thanks!

Upvotes: 3

Views: 604

Answers (1)

Tanaike
Tanaike

Reputation: 201378

In my environment, I confirmed that appProperties can be retrieved using files.list and files.get of googleapis with v29.0.0. And I thought about the possibility of the reason for your situation. So can you confirm the following point?

When I read the document of Custom File Properties, it says as follows.

Properties are accessed using the properties (visible to all apps) and appProperties (restricted to single apps) fields on files

I investigated about this. As a sample, it supposes that {"key1": "value1"} was written to appProperties and properties by client_id_A.

  • For appProperties, when the appProperties is read, only the client ID which is the same with the client ID used when appProperties was written can read it.
    • Namely, when the access token retrieved from client_id_B is used, it cannot read appProperties written by client_id_A.
  • For properties, when the properties is read, it can be read by various client IDs.
    • Namely, even if the access token retrieved from client_id_B is used, it can read properties written by client_id_A.

From these results, appProperties and properties can be used as "Private" and "Public", respectively.

Using this, can you confirm your situation again? If you will write appProperties using node.js, you can use the following script. By this, you can confirm that you can write and read appProperties using the same client ID.

drive.files.update({
  fileId: "### file ID ###",
  resource: {"appProperties": {"key": "value"}},
  fields: 'id,appProperties',
});

If this was not useful for your situation, I'm sorry.

Upvotes: 2

Related Questions