douzuqin3467 2013-11-09 00:26
浏览 50

使用google-drive-api创建子文件夹并使用PHP返回id

I can create the sub folder just fine with the code below but I just can't return the id.

I would like to get the id and/or the link to the folder so I can add them to my database.

Currently the below creates the folder but just returns "//" as the id!

Thanks for your help

<?php

if ($client->getAccessToken()) {

$file = new Google_DriveFile();

//Setup the Folder to Create
$file->setTitle('Project  Folder');
$file->setDescription('A Project Folder');
$file->setMimeType('application/vnd.google-apps.folder');

//Set the ProjectsFolder Parent
$parent = new Google_ParentReference();
$parent->setId('0B9mYBlahBlahBlah');
$file->setParents(array($parent));

//create the ProjectFolder in the Parent
$createdFile = $service->files->insert($file, array(
    'mimeType' => 'application/vnd.google-apps.folder',
));

// print_r($createdFile);
print "folder created sucessfully";
echo "folder id is" . $createdFile->id;
}
?>
  • 写回答

3条回答 默认 最新

  • duandi4815 2013-11-09 00:36
    关注

    Maybe it's not fancy way but this is my method to get folder ID:

    $service = new Google_DriveService($client);
    
    $files = $service->files->listFiles();
    foreach ($files['items'] as $item) {
        if ($item['title'] == 'your_folder_name') {
            $folderId = $item['id'];
        break;
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码