4
votes

Im currently making a website with Google Drive integration and im running into a problem. The API docs state that i can sort a list of files based on modifiedTime but when i try to make this request, im getting an invalid value response.

Error calling GET https://www.googleapis.com/drive/v2/files?q=%270Bxm0A6z2alblOHk1ZEtrcUF0Slk%27+in+parents&orderBy=folder%2CmodifiedTime%2Ctitle&key=HIDDEN: (400) Invalid Value

Excerpt from the Google Drive API docs:

A comma-separated list of sort keys. Valid keys are 'createdTime', 'folder', 'modifiedByMeTime', 'modifiedTime', 'name', '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.

This is my query (PHP) :

public function listFiles($folder_id)
{
    return $this->drive->files->listFiles([
        "q" => "'$folder_id' in parents",
        "orderBy" => "folder,modifiedTime,title"
    ]);
}

If i remove the modifiedTime from the orderBy values. The query completes successfully.

1

1 Answers

5
votes

Found it! Looks like im using v2 of the Google Drive SDK and looking at the v3 docs..

In v3 the orderBy query value changed from modifiedDate to modifiedTime.

Knowing this I changed the code to:

public function listFiles($folder_id)
{
    return $this->drive->files->listFiles([
        "q" => "'$folder_id' in parents",
        "orderBy" => "folder,modifiedDate desc,title"
    ]);
}

This allows me to sort properly =)