我一直在尝试使用php通过 service-account 将文件上传到我的google驱动器帐户。我猜该文件已成功上传,因为我可以打印文件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>';