目标:尝试使用php-curl在zoho工作驱动器中创建一个文件
注意:我已经检查了oauth并且我正在使用正确的oauth。另外,我正在使用正确的父ID。
error-recieved : {"errors":[{"id":"F000","title":"General
例外“}]}
使用的代码:
work_drive_create_file($oauth);
function work_drive_create_file($oauth){
$apiUrl = "https://workdrive.zoho.com/api/v1/files";
$data ='{
"data": {
"attributes": {
"name": "Untitled Spreadsheet",
"service_type": "zohosheet",
"parent_id": "0nk78318a1771da934f22939e4a00d8aab225"
},
"type": "files"
}
}';
$headers = array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data),
sprintf('Authorization: Zoho-oauthtoken %s', $oauth)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_POSTFIELDS ,$data);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
$response = curl_exec($ch);
print_r(json_decode($response));
curl_close($ch);
return $response;
}
我也想知道“服务类型”的价值,如果它的文件代替zohosheet。
@Rishabh Kushwaha你错过了在Rest API中设置User agent Header。
如Per RFC 7231:
用户代理应该在每个请求中发送User-Agent字段,除非特别配置不这样做。
您可以使用像User-Agent这样的简单用户代理标头:“PHP 5.7.1”。尝试使用适当的用户代理标头,其余的api将按预期工作。这对于监视请求源的来源非常有用,并且可以在访问统计日志中轻松找到您的测试。
api / v1 / files是创建文件的端点。所以api调用看起来如下所示:
$ apiUrl = https://workdrive.zoho.com/api/v1/files
要创建文档:
service_type =“zw”
创建演示文稿
SERVICE_TYPE =“zohoshow”
您可以在我们的API文档here上找到大多数问题的答案。