繁体   English   中英

如何查看通过PHP上传到Google驱动器的文件?

[英]How to see files uploaded to google drive via PHP?

我一直试图使用php通过service-account将文件上传到我的Google Drive帐户。 我猜该文件已成功上传,因为我可以打印文件ID,文件创建时间和所有其他信息。

这是我的问题:登录到Google云端硬盘帐户后,看不到任何上传的文件。 文件隐藏在哪里或该怎么办?

这是代码:

require __DIR__ . '/vendor/autoload.php'; //api
$serviceAccount     = "xxx@xxxxxx.iam.gserviceaccount.com";
$key_file       = "mykey-goes-here.p12";
$auth = new Google_Auth_AssertionCredentials(
                    $serviceAccount,
                    array('https://www.googleapis.com/auth/drive.file'),
                    file_get_contents($key_file)
                    );
$client = new Google_Client();
$client->setAssertionCredentials( $auth );

$service = new Google_Service_Drive($client);

 $file = new Google_Service_Drive_DriveFile();
  $file->setTitle("my file name");
 $file->setDescription('testing desc');
 $file->setMimeType('text/plain');
                // Provide file name here and path in below 

  $result = $service->files->insert($file, array(
  'data' => file_get_contents("test.txt"),
//'mimeType' => 'text/plain',
  'mimeType' => 'application/octet-stream',
  'uploadType' => 'media',
 //'uploadType' => 'multipart'
));

 // Uncomment the following line to print the File ID
   printf("File ID: %s\n", $result->id);


echo "<br><br>";
echo '<pre>'; print_r($result); echo'</pre>';

解:

我发现服务帐户上传的文件无法通过UI使用。

为了解决该问题,需要委派/授权应用程序使用所述服务帐户。 链接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM