我可能遗漏了一些非常明显的东西,但是如果不解析其中的一些值,如何使用文件ID在Google中获取文件的类型(文档、电子表格、演示文稿或绘图)。
我需要从共享文件夹中获取文件列表-没有问题。
然后,我需要处理这些文件的文件类型-所以文件,电子表格,绘图,演示文稿或文件夹。这是有问题的,因为我不知道如何获得文件类型。
到目前为止,我已经尝试过:
文件夹中的获取文件列表:
$obj = $service->children->listChildren($folderId);没问题。
遍历文件并使用文件ID:获取文件元数据
foreach ($obj->items as $item):
$fileId = $item->id;
$file = $service->files->get($fileId);
// Rest of code here
endforeach;没问题。
Get文件类型
我不知道如何从$file对象获取文件类型。
最后,我做了一件杂乱无章的工作:
if (strpos($file->embedLink,'document') !== false) $fileType = 'document';
if (strpos($file->embedLink,'spreadsheet') !== false) $fileType = 'spreadsheet';有更简单的方法吗?
发布于 2014-08-03 08:08:36
所以,简单地说,就是:
$file->mimeType.你得到:
application/vnd.google-apps.document
application/vnd.google-apps.spreadsheet以此类推
扫描得太快了。
https://stackoverflow.com/questions/25082095
复制相似问题