簡體   English   中英

在通過 Google Drive API 上傳的 Google Drive 中找不到我的文件

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM