简体   繁体   中英

Sorting a list of files by modifiedTime (Google Drive API)

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.

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 =)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM