代码之家  ›  专栏  ›  技术社区  ›  Knight

为什么Google\u Service\u驱动器文件的属性只返回null?

  •  2
  • Knight  · 技术社区  · 7 年前

    public function getTitlesAndIDs($folderID)
    {
    
        // $capabilities = new \Google_Service_Drive_DriveFileCapabilities();
        // $capabilities->canListChildren = true;
        $files = $this->driveService->files->listFiles();
    
        var_dump($files);
    }
    

    尝试添加功能也只会返回NULL。当我运行listFiles()时,我得到如下输出:

    ["files"]=>
      array(100) {
        [0]=>
        object(Google_Service_Drive_DriveFile)#77 (65) {
          ["collection_key":protected]=>
          string(6) "spaces"
          ["appProperties"]=>
          NULL
          ["capabilitiesType":protected]=>
          string(42) "Google_Service_Drive_DriveFileCapabilities"
          ["capabilitiesDataType":protected]=>
          string(0) ""
          ["contentHintsType":protected]=>
          string(42) "Google_Service_Drive_DriveFileContentHints"
          ["contentHintsDataType":protected]=>
          string(0) ""
          ["createdTime"]=>
          NULL
          ["description"]=>
          NULL
          ["explicitlyTrashed"]=>
          NULL
          ["fileExtension"]=>
          NULL
          ["folderColorRgb"]=>
    ...
    

    提前谢谢。

    3 回复  |  直到 7 年前
        1
  •  4
  •   Linda Lawton - DaImTo    7 年前

    $service = new Google_Service_Drive($client);
    
    // Print the names and IDs for up to 10 files.
    $optParams = array(
      'pageSize' => 10,
      'fields' => 'nextPageToken, files(id, name)'
    );
    $results = $service->files->listFiles($optParams);
    
    if (count($results->getFiles()) == 0) {
      print "No files found.\n";
    } else {
      print "Files:\n";
      foreach ($results->getFiles() as $file) {
        printf("%s (%s)\n", $file->getName(), $file->getId());
      }
    }
    

    代码从中删除 PHP Quickstart

        2
  •  3
  •   iloo    7 年前

    除了@DalmTo所说的之外,还有一件重要的事情需要明确指出:你收到了 NULL 'fields' 作为可选参数。

        3
  •  1
  •   cloudxix    4 年前

    id, name, kind description ,开发者可以通过 properties appProperties .

    https://developers.google.com/drive/api/v3/properties

    属性

    在整个Google Drive V3文档中,“属性”一词也指 元数据 https://developers.google.com/drive/api/v3/reference/files

    属性 使用PHP,但在Google Drive V3中 属性

    通过修改上面的示例代码,我能够检索自定义属性。

    $service = new Google_Service_Drive($client);
    
    // Print the names, IDs and properties for up to 10 files.
    $optParams = array(
      'pageSize' => 10,
      'fields' => 'nextPageToken, files(id, name, properties)'
    );
    $results = $service->files->listFiles($optParams);
    
    if (count($results->getFiles()) == 0) {
      print "No files found.\n";
    } else {
      print "Files:\n";
      foreach ($results->getFiles() as $file) {
        printf("%s (%s)\n", "name: ".$file->getName(), "ID: ".$file->getId());
          foreach ($file->getProperties() as $key => $value) {
            printf("%s%s\n","-key: ".$key,", value: ".$value);
        }
      }
    }
    

    属性