Google drive api google drive api不知道它将文件保存在哪里,但在获取文件时,它会显示保存的文件,而不会显示其他文件

Google drive api google drive api不知道它将文件保存在哪里,但在获取文件时,它会显示保存的文件,而不会显示其他文件,google-drive-api,Google Drive Api,我用谷歌驱动api插入了一个文本文件 构建服务 function buildService() { $DRIVE_SCOPE = 'https://www.googleapis.com/auth/drive'; $SERVICE_ACCOUNT_EMAIL = 'xxxx@developer.gserviceaccount.com'; if($_SERVER['HTTP_HOST'] == 'localhost') $SERVICE_ACCOUNT_PKCS12_FILE_PATH = 'x

我用谷歌驱动api插入了一个文本文件

构建服务

function buildService() {

$DRIVE_SCOPE = 'https://www.googleapis.com/auth/drive';
$SERVICE_ACCOUNT_EMAIL = 'xxxx@developer.gserviceaccount.com';

if($_SERVER['HTTP_HOST'] == 'localhost')
$SERVICE_ACCOUNT_PKCS12_FILE_PATH = 'xxxxxxxx-privatekey.p12';
else
$SERVICE_ACCOUNT_PKCS12_FILE_PATH = $_SERVER['DOCUMENT_ROOT'].'/xxxxx-privatekey.p12';

  $key = file_get_contents($SERVICE_ACCOUNT_PKCS12_FILE_PATH);
  $auth = new Google_AssertionCredentials(
      $SERVICE_ACCOUNT_EMAIL,
      array($DRIVE_SCOPE),
      $key);
  $client = new Google_Client();
  $client->setUseObjects(true);
  $client->setAssertionCredentials($auth);
  return new Google_DriveService($client);
}
检索文件

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;
}
创建实例并插入

$service = buildService();

$file = new Google_DriveFile();
$file->setTitle('My document');
$file->setDescription('A test document');
$file->setMimeType('text/plain');

$data = "contents";

$createdFile = $service->files->insert($file, array('data' => $data,'mimeType' =>'text/plain',));

print_r($createdFile);

echo '<br>------<br>';
$service=buildService();
$file=new Google_DriveFile();
$file->setTitle(“我的文档”);
$file->setDescription(“测试文档”);
$file->setMimeType('text/plain');
$data=“contents”;
$createdFile=$service->files->insert($file,array('data'=>$data,'mimeType'=>'text/plain',);
打印文件($createdFile);
回声'
----
';
检索文件

$ret = retrieveAllFiles($service);

echo '<pre>';
print_r($ret);
$ret=retrieveAllFiles($service);
回声';
印刷费($ret);
  • 在第一次调用中,我插入了一个文件

  • 在第二次调用中,我尝试列出所有文件

  • 当我尝试列出时,我只能看到插入的文件,而不能看到通过登录docs.google.com在驱动器中看到的其他文件。我已经有6个文件在线

  • 根据文档,我使用私钥和服务帐户电子邮件创建了服务帐户


  • 那么该文件将存储在哪里?我如何在google drive的根目录中列出所有其他文件?

    您正在将文件插入由服务帐户表示的应用程序拥有的帐户中


    如果要管理(插入/list/…)其他域用户的驱动器帐户中的文件,则必须执行域范围的委派:

    不,这是我和我的帐户。我想在不受干扰的情况下,在后台将文件从我的网站复制到google drive。此外,是否可以在浏览器中查看我使用drive.google.com插入的所有文件。我试过了,但看不到插入的文件。建议…?您进行身份验证的方式是用于服务帐户的方式。如果您只需要访问您的帐户,那么标准的身份验证过程就足够了。您可以请求脱机访问以在后台插入文件哦。。。这就是我一直在寻找的。。。我在驱动器api文档中没有看到任何与脱机访问相关的主题。。。你能在这里写一封推荐信吗?同时,我正在检查它。。。第一次进入GoogleDriveAPI需要很长时间…请查看有关OAuth流的更多详细信息