Mr. Lance E Sloan
Mr. Lance E Sloan

Reputation: 3387

existence or count of children in file resource?

The files resource, which is returned by the files.list and other methods, includes a list of parents for each file. It would be extremely helpful if files also included some indication of children. An integer property with the count of children would be best, but a Boolean flag indicating whether children exist would be fine. Could that be added to the API, Google folks?

I ask because I'm writing an application that displays an expandable tree of the user's Google Drive contents. The tree initially displays the top level of their drive with all folders collapsed. As the user expands folders, new queries are sent to the GD API to get the contents of each one. However, empty folders are to be displayed without an expansion icon at all. In order to do that, as the list of children in a folder is processed, if a child is a folder, another query must be run for that specific folder to discover whether it has children. It would be so much better if the files resource included a count of its children or a flag indicating their existence. It would reduce the number of queries, network traffic, and processing time.

Upvotes: 0

Views: 455

Answers (2)

Ronan
Ronan

Reputation: 4321

Various work-around I found were all based on a looping solution over the children items count returned by each API call. Next API call must be then updated with the nextPageToken received from each response. A maxResult may be set to 1000 (max allowed).

Examples:

Upvotes: 0

pinoyyid
pinoyyid

Reputation: 22306

I doubt very much it will happen. The issue is that there could be thousands of children and to include an array of that size within the file object would break and time out.

The children feed https://developers.google.com/drive/v2/reference/children/list is there for that specific purpose, and supports pagination.

Upvotes: 1

Related Questions