繁体   English   中英

在 google drive php 中创建一个文件夹

[英]Create a folder in google drive php

有什么办法可以使用PHP在谷歌驱动器上创建一个文件夹吗? 在过去的 72 小时内,我一直在搜索所有网络,但没有任何结果。 你们觉得怎么样? 谢谢 !

这是使用 Google Drive API v3 和 OAuth 访问令牌的更新方法:

$googleClient = new \Google_Client();
$googleClient->setApplicationName('My App');
$googleClient->setAccessToken(env('GOOGLE_OAUTH_ACCESS_TOKEN'));
$googleClient->setClientId(env('GOOGLE_APP_ID'));
$googleClient->setClientSecret(env('GOOGLE_APP_SECRET'));

if ($googleClient->isAccessTokenExpired()) {
    $googleClient->fetchAccessTokenWithRefreshToken();
}

$api = new \Google_Service_Drive($client);

$file = new \Google_Service_Drive_DriveFile();
$file->setName('Folder Name');
$file->setMimeType('application/vnd.google-apps.folder');

$folder = $api->files->create($file);

创建文件夹:

“在 Drive API 中,文件夹本质上是一个文件 — 由特殊文件夹 MIME 类型 application/vnd.google-apps.folder 标识。您可以通过插入具有此 MIME 类型和文件夹标题的文件来创建新文件夹。设置文件夹标题时不要包含扩展名。

要为特定文件夹创建子文件夹,请在文件的 parents 属性中指定正确的 ID。 例如,要在 id 值为 0ADK06pfg 的“images”文件夹中创建文件夹“pets”:

POST https://www.googleapis.com/drive/v2/files
Authorization: Bearer {ACCESS_TOKEN}
Content-Type: application/json
...
{
  "title": "pets",
  "parents": [{"id":"0ADK06pfg"}]
  "mimeType": "application/vnd.google-apps.folder"
}

来源: https : //developers.google.com/drive/folder

示例: https : //developers.google.com/drive/examples/php

暂无
暂无

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

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