使用google-drive-api创建一个子文件夹,并使用PHP返回id [英] Create a sub folder using google-drive-api and return the id with PHP

查看:205
本文介绍了使用google-drive-api创建一个子文件夹,并使用PHP返回id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以用下面的代码创建子文件夹,但是我不能返回id。

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

我想获得文件夹的id和/或链接,以便将它们添加到我的数据库。

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

目前,下面的内容会创建文件夹,但仅返回//作为ID!

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;
}
?>


推荐答案

$files = $service->files->listFiles(array('maxResults' => 1));
var_dump($files['items'][0]['id']); 

这篇关于使用google-drive-api创建一个子文件夹,并使用PHP返回id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆