![](/img/trans.png)
[英]I can't see the files and folders created via api in my Google Drive using php
[英]Can't find my files in google drive that uploaded via Google Drive API
我正在将文件上传到我的 Google Drive 帐户。 这是代码:
putenv('GOOGLE_APPLICATION_CREDENTIALS=xxxx.json');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(Google_Service_Drive::DRIVE);
$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
$client->setRedirectUri($redirect_uri);
$tempfile = "birds-image-11.jpg";
$file = new Google_Service_Drive_DriveFile(array(
'name' => 'tc-test.jpg',
));
$service = new Google_Service_Drive($client);
$result = $service->files->create($file, array(
'data' => file_get_contents($tempfile),
'mimeType' => 'application/octet-stream',
'uploadType' => 'media',
'fields' => 'id, name,kind'
));
printf("File ID: %s\n", $result->id);echo '<br>';
printf("File Name: %s\n", $result->name);echo '<br>';
printf("File Kind: %s\n", $result->kind); echo '<br>';
我可以看到返回的 ID、名称和种类。 所以这意味着文件已经上传对吗? 但是当我进入我的谷歌驱动器时,我看不到这些文件。
如果我从 api $service->files->listFiles();
列出文件$service->files->listFiles();
我可以看到上传的文件对象返回。
为什么我在我的驱动器 ( https://drive.google.com/drive/my-drive ) 中看不到它,我应该在哪里查找文件?
顺便说一下,我正在为 api 使用服务帐户。
您还需要设置文件的父文件夹,可以是用户的“我的驱动器”或任何其他文件夹。
通过 Google Drive API 上传文件时指定文件夹名称
https://developers.google.com/drive/v3/reference/files/update
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.