如何检查谷歌驱动器中是否已存在文件夹?

时间:2016-04-12 10:40:31

标签: php curl google-drive-api

我正在尝试创建一个php脚本,将文件从服务器上传到客户端的google驱动器,我已设法上传文件,甚至在我使用curl创建的文件夹中,但问题是我需要检查是否客户端已经有一个具有特定名称的文件夹,如果是,我必须获取id并将文件上传到该文件夹​​的id,这是我用来制作文件的代码:

$folder_fields = "{\"title\":\"innitel\",
    \"parents\":\"[{}]\",
    \"mimeType\":\"application/vnd.google-apps.folder\"}";


$ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://www.googleapis.com/drive/v2/files");
    curl_setopt($ch, CURLOPT_PORT, 443);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $folder_fields);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HTTPHEADER, ARRAY("Authorization: Bearer $access_token",
    "Content-Type: application/json"));
    $reponse = curl_exec($ch);

此方法将在每次运行脚本时创建一个具有相同名称的文件夹。 有办法吗?

注意:我不能使用google-api-php-client,因为服务器的php版本是5.3,不支持。

0 个答案:

没有答案