我可以通过 json 到 Drive 文件夹中在 Google Drive 中创建一个文件:
$data = array(
"title" => $_FILES['file']['name'],
"parents" => array(array(
"kind" => "drive#parentReference",
"id" => $parent_id
)),
"mimeType" => "application/pdf"
);
$data = json_encode($data);
$url = "https://www.googleapis.com/drive/v2/files?oauth_token=".$accessToken;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
但我找不到在其上添加 PDF 文件的方法,因为 Google Drive 文档上没有指定 json 属性。
我必须在哪里添加文件内容?
这可能吗?
我是否必须先上传文件才能上传/驱动器,然后再上传带有文件夹 ID 的元数据?我觉得这没有什么意义。