使用Google Drive API上传后如何获取Google Drive文件ID?

时间:2018-12-11 06:54:44

标签: php laravel codeigniter google-api google-drive-api

我正在使用PHP Google Drive Api(Uploading files to Google Drive with PHP)在google drive上上传文件,我想知道上传后如何获取fileId,因此可以将其用作HTML中的SRC。有人知道吗谢谢。

1 个答案:

答案 0 :(得分:1)

您可以在examples的官方Google's API PHP Client repository中找到问题的答案:

$file = new Google_Service_Drive_DriveFile();
$result = $service->files->create(
    $file,
    [
      'data' => file_get_contents('path/to/your/file'),
      'mimeType' => 'application/octet-stream',
      'uploadType' => 'media',
    ]
);

// $result->id is the ID you're looking for
// $result->name is the name of uploaded file

请参见下面的HTML示例,了解如何使用$result对象:

<a href="https://drive.google.com/open?id=<?= $result->id ?>" target="_blank"><?= $result->name ?>
相关问题