Result order in the Google Drive SDK

Viewed 711

Can we order a file list with the Google Drive Api (by title, kind or last update)? This obviously can't be done on the client side as we're not supposed to get the whole list in one bit but can't figure out how to order it on the server side. Thanks for your help

2 Answers

In 2022 (and probably for many years already), this is possible via the orderBy parameter, documented at https://developers.google.com/drive/api/v3/reference/files/list:

A comma-separated list of sort keys. Valid keys are 'createdTime', 'folder', 'modifiedByMeTime', 'modifiedTime', 'name', 'name_natural', 'quotaBytesUsed', 'recency', 'sharedWithMeTime', 'starred', and 'viewedByMeTime'. Each key sorts ascending by default, but may be reversed with the 'desc' modifier. Example usage: ?orderBy=folder,modifiedTime desc,name. Please note that there is a current limitation for users with approximately one million files in which the requested sort order is ignored.

Related