Zoho workdrive api "General Exception" 错误

Zoho workdrive api "General Exception" error

目标:尝试使用 php-curl

在 zoho workdrive 中创建文件

注意:我已经检查了 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;

              }

我还想知道 "service-type" 的值,如果它是代替 zohosheet 的文档。

api/v1/files是创建文件的端点。 所以 api 调用如下所示:

$apiUrl = https://workdrive.zoho.com/api/v1/files

创建文档:

service_type = “zw”

创建演示文稿

service_type=“zohoshow”

您可以在我们的 API 文档 here 中找到大部分问题的答案。

@Rishabh Kushwaha 您错过了在其余 API 中设置用户代理 Header。

根据RFC 7231

A user agent SHOULD send a User-Agent field in each request unless specifically configured not to do so.

您可以使用简单的用户代理 header,例如 User-Agent:“PHP 5.7.1”。尝试使用适当的用户代理 header,其余 api 将按预期工作。这应该有助于监视请求来源,并且还可以轻松地在访问统计日志中找到您的测试。