Fao*_*ech 1 php directory google-drive-api google-drive-realtime-api
我们有什么方法可以使用PHP在谷歌驱动器上创建一个文件夹?过去72小时我一直在搜索所有网页但没有结果.你们觉得怎么样?谢谢 !
krc*_*hun 12
这是使用 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);
Run Code Online (Sandbox Code Playgroud)
Pau*_*ert 10
"在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"
}
Run Code Online (Sandbox Code Playgroud)
资料来源:https://developers.google.com/drive/folder
示例:https://developers.google.com/drive/examples/php
| 归档时间: |
|
| 查看次数: |
7324 次 |
| 最近记录: |