简体   繁体   English

按ModifiedTime排序文件列表(Google Drive API)

[英]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. 我目前正在建立一个与Google Drive集成的网站,我遇到了问题。 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. API文档声明我可以根据modifiedTime对文件列表进行排序,但是当我尝试发出此请求时,我会得到无效的值响应。

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

Excerpt from the Google Drive API docs: 摘自Google Drive API文档:

A comma-separated list of sort keys. 以逗号分隔的排序键列表。 Valid keys are 'createdTime', 'folder', 'modifiedByMeTime', 'modifiedTime', 'name', 'quotaBytesUsed', 'recency', 'sharedWithMeTime', 'starred', and 'viewedByMeTime'. 有效键是'createdTime','folder','modifiedByMeTime','modifiedTime','name','quotaBytesUsed','recency','sharedWithMeTime','starred'和'seenByMeTime'。 Each key sorts ascending by default, but may be reversed with the 'desc' modifier. 默认情况下,每个键按升序排序,但可以使用'desc'修饰符进行反转。 Example usage: ?orderBy=folder,modifiedTime desc,name. 用法示例:?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) : 这是我的查询(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. 如果我从orderBy值中删除modifiedTime The query completes successfully. 查询成功完成。

Found it! 找到了! Looks like im using v2 of the Google Drive SDK and looking at the v3 docs.. 看起来我正在使用Google Drive SDK的v2并查看v3文档..

In v3 the orderBy query value changed from modifiedDate to modifiedTime . 在v3中,orderBy查询值从modifiedDatemodifiedTime

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 =) 这允许我正确排序=)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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