未定义 属性:Google_Service_Books::$文件

Undefined property: Google_Service_Books::$files

我正在尝试通过本地 PHP 应用程序从我的 Google 驱动器中获取文件列表,这是我所拥有的:

$client = new Google_Client();
$client->setApplicationName("My Application");
$client->setDeveloperKey("AIzaSyAmWcZArf7NCk4d65HoKZzLENCJ6cx9fNg");
$service = new Google_Service_Books($client);


 /**
 * Retrieve a list of File resources.
 *
 * @param Google_Service_Drive $service Drive API service instance.
 * @return Array List of Google_Service_Drive_DriveFile resources.
 */
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;
}


retrieveAllFiles($service); 

直接取自docs

当我 运行 时出现以下错误:

有人知道为什么会这样吗?

你不应该使用 Google_Service_Drive 而不是 Google_Service_Books 吗?

Google_Service_Drive:

class Google_Service_Drive extends Google_Service
{
    /** View and manage the files and documents in your Google Drive. */
    const DRIVE = "https://www.googleapis.com/auth/drive";
    /** View and manage its own configuration data in your Google Drive. */
    const DRIVE_APPDATA = "https://www.googleapis.com/auth/drive.appdata";
    /** View your Google Drive apps. */
    const DRIVE_APPS_READONLY = "https://www.googleapis.com/auth/drive.apps.readonly";
    /** View and manage Google Drive files that you have opened or created with this app. */
    const DRIVE_FILE = "https://www.googleapis.com/auth/drive.file";
    /** View metadata for files and documents in your Google Drive. */
    const DRIVE_METADATA_READONLY = "https://www.googleapis.com/auth/drive.metadata.readonly";
    /** View the files and documents in your Google Drive. */
    const DRIVE_READONLY = "https://www.googleapis.com/auth/drive.readonly";
    /** Modify your Google Apps Script scripts' behavior. */
    const DRIVE_SCRIPTS = "https://www.googleapis.com/auth/drive.scripts";
    public $about;
    public $apps;
    public $changes;
    public $channels;
    public $children;
    public $comments;
    public $files;
    public $parents;
    public $permissions;
    public $properties;
    public $realtime;
    public $replies;
    public $revisions;

Google_Service_Books:

class Google_Service_Books extends Google_Service
{
    /** Manage your books. */
    const BOOKS = "https://www.googleapis.com/auth/books";
    public $bookshelves;
    public $bookshelves_volumes;
    public $cloudloading;
    public $layers;
    public $layers_annotationData;
    public $layers_volumeAnnotations;
    public $myconfig;
    public $mylibrary_annotations;
    public $mylibrary_bookshelves;
    public $mylibrary_bookshelves_volumes;
    public $mylibrary_readingpositions;
    public $promooffer;
    public $volumes;
    public $volumes_associated;
    public $volumes_mybooks;
    public $volumes_recommended;
    public $volumes_useruploaded;