[英]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"
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.