Google Drive API:获取父文件夹的标题 [英] Google Drive API: Get titles of the parent folders

查看:279
本文介绍了Google Drive API:获取父文件夹的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的谷歌代码:

 函数retrieveAllFiles($ service){
$ result = array( );
$ pageToken = NULL;

do {
try {
$ parameters = array();
if($ pageToken){
$ parameters ['pageToken'] = $ pageToken;
}
$ files = $ service-> files-> listFiles($ parameters);

$ result = array_merge($ result,$ files-> getItems());
$ pageToken = $ files-> getNextPageToken();
} catch(Exception $ e){
print发生错误:。 $ E->的getMessage();
$ pageToken = NULL;
}
} while($ pageToken);
返回$ result;
}

我知道我可以这样做:

  $ files = retrieveAllFiles($ service); 
foreach($ files as $ file){
$ id = $ file-> getId();
$ title = $ file-> getTitle()
}

我们也可以通过以下方式获取文件的父母:

  foreach($ files as $ file){
$ parents = $文件 - > getParents();
}

是否有可能在不调用其他请求的情况下获取父文件夹的标题?例如:

  foreach($ files as $ file){
$ parents = $ file-> getParents() ;
foreach($ parents作为$ parent){
$ parent_title = $ parent-> getTitle(); //不存在


code
$ b我知道它会抛出一个错误但有没有其他的选择来达到这个要求?

不,这是不可能的。将一个文件的元数据嵌入到另一个文件中会导致难看的API。 Drive API是一个非常干净的REST API,这意味着您需要提出多个请求。



我已经稍微修改了您的问题,以澄清文件可以有多个家长。


I have this code from google:

function retrieveAllFiles($service) {
$result = array();
$pageToken = NULL;

do {
 try {
   $parameters = array();
   if ($pageToken) {
     $parameters['pageToken'] = $pageToken;
   }
   $files = $service->files->listFiles($parameters);

   $result = array_merge($result, $files->getItems());
   $pageToken = $files->getNextPageToken();
  } catch (Exception $e) {
   print "An error occurred: " . $e->getMessage();
   $pageToken = NULL;
  }
 } while ($pageToken);
return $result;
}

I know i can do this:

$files = retrieveAllFiles($service);
foreach($files as $file){
   $id = $file->getId();
   $title = $file->getTitle()
}

We can also fetch the parents of the file by:

foreach($files as $file){
   $parents = $file->getParents();
}

Is it possible to get the titles of the parent folders without calling another request? like:

foreach($files as $file){
   $parents = $file->getParents();
   foreach($parents as $parent){
     $parent_title = $parent->getTitle(); //NOT EXISTING
   }
}

I know that it throws an error but is there other alternative to achieve this requirement?

解决方案

No it's not possible. Embedding the meta data of one file within another would make for an ugly API. The Drive API is a very clean REST API, which means that you'll need to make multiple requests.

I've edited your question slightly to clarify that a file can have more than one parent.

这篇关于Google Drive API:获取父文件夹的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆