按修改时间对文件列表进行排序(Google 驱动器 API)
Sorting a list of files by modifiedTime (Google Drive API)
我目前正在制作一个带有 Google 驱动器集成的网站,我 运行 遇到了问题。 API 文档声明我可以根据 modifiedTime
对文件列表进行排序,但是当我尝试发出此请求时,我收到无效值响应。
调用 GET 时出错 https://www.googleapis.com/drive/v2/files?q=%270Bxm0A6z2alblOHk1ZEtrcUF0Slk%27+in+parents&orderBy=folder%2CmodifiedTime%2Ctitle&key=HIDDEN: (400) 无效值
摘自 Google Drive API 文档:
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.
这是我的查询 (PHP) :
public function listFiles($folder_id)
{
return $this->drive->files->listFiles([
"q" => "'$folder_id' in parents",
"orderBy" => "folder,modifiedTime,title"
]);
}
如果我从 orderBy
值中删除 modifiedTime
。查询成功完成。
找到了!看起来我正在使用 Google Drive SDK 的 v2 并查看 v3 文档..
在 v3 中,orderBy 查询值从 modifiedDate
更改为 modifiedTime
。
知道这一点后,我将代码更改为:
public function listFiles($folder_id)
{
return $this->drive->files->listFiles([
"q" => "'$folder_id' in parents",
"orderBy" => "folder,modifiedDate desc,title"
]);
}
这让我可以正确排序 =)
我目前正在制作一个带有 Google 驱动器集成的网站,我 运行 遇到了问题。 API 文档声明我可以根据 modifiedTime
对文件列表进行排序,但是当我尝试发出此请求时,我收到无效值响应。
调用 GET 时出错 https://www.googleapis.com/drive/v2/files?q=%270Bxm0A6z2alblOHk1ZEtrcUF0Slk%27+in+parents&orderBy=folder%2CmodifiedTime%2Ctitle&key=HIDDEN: (400) 无效值
摘自 Google Drive API 文档:
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.
这是我的查询 (PHP) :
public function listFiles($folder_id)
{
return $this->drive->files->listFiles([
"q" => "'$folder_id' in parents",
"orderBy" => "folder,modifiedTime,title"
]);
}
如果我从 orderBy
值中删除 modifiedTime
。查询成功完成。
找到了!看起来我正在使用 Google Drive SDK 的 v2 并查看 v3 文档..
在 v3 中,orderBy 查询值从 modifiedDate
更改为 modifiedTime
。
知道这一点后,我将代码更改为:
public function listFiles($folder_id)
{
return $this->drive->files->listFiles([
"q" => "'$folder_id' in parents",
"orderBy" => "folder,modifiedDate desc,title"
]);
}
这让我可以正确排序 =)