Google_Service_Drive retrieveListOfAllFiles仅返回一个文件

ato*_*dam 1 php google-drive-api google-api-php-client

当我从php运行API时,返回的唯一项目是"如何开始使用Drive"文件,该文件不在文件夹中,但是当我从API网页运行retrieveListOfAllFiles()时,我看到驱动器中的所有文件.这是代码.

set_include_path(ABSPATH . "path-to/api/google-api-php-client/src/");
require_once "Google/Client.php";
require_once "Google/Service/Drive.php";
require_once "Google/Auth/OAuth2.php";
require_once "Google/Auth/AssertionCredentials.php";

  define('CLIENT_ID', 'xxxxx');
  define('SERVICE_ACCOUNT_NAME', 'xxxxx');
  $key    = file_get_contents(ABSPATH . "path-to-.p12");
  $scopes = array('https://www.googleapis.com/auth/drive.readonly');


  $client = new Google_Client();
  $client->setApplicationName("xxxx");

  if (isset($_SESSION['service_token'])) {
    $client->setAccessToken($_SESSION['service_token']);
  }

  $auth = new Google_Auth_AssertionCredentials(
    SERVICE_ACCOUNT_NAME,
    $scopes,
    $key
  );

  $client->setAssertionCredentials($auth);

  if ($client->getAuth()->isAccessTokenExpired()) {
    $client->getAuth()->refreshTokenWithAssertion($auth);
  }

  $_SESSION['service_token'] = $client->getAccessToken();

  $service = new Google_Service_Drive($client);

  $files = retrieveAllFiles($service);
Run Code Online (Sandbox Code Playgroud)

文件仅返回"如何开始使用驱动器"文件 - 从此页面进行API测试:https://developers.google.com/drive/v2/reference/files/list返回驱动器中的所有文件.

ID正确,.p12文件是新的和加载,我不知道出了什么问题.

我也注意到,如果我var_dump()的输出

dump($service->files->listFiles(array()));
Run Code Online (Sandbox Code Playgroud)

我也只获得单曲"如何开始使用驱动器"文件.所以,即使我没有收到任何OAuth2错误,并获得密钥令牌等,我想要列出文件的驱动器也没有被访问.

ato*_*dam 7

问题解决了.必须与API用户共享一个驱动器中的文件夹 - 以@ developer.gserviceaccount.com结尾的电子邮件 - 我在任何地方都没有看到这些文件...也许我是盲目的.但似乎这些API文档已经过时了.