Zoho WorkDrive API“常规异常”错误

时间:2019-02-13 09:38:57

标签: zoho

Objetcive:尝试使用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;

              }

如果它是代替zohosheet的文档,我也想知道“服务类型”的值。

2 个答案:

答案 0 :(得分:2)

@Rishabh Kushwaha您错过了在Rest API中设置用户代理标题的问题。

根据RFC 7231

  

用户代理应在每个请求中发送用户代理字段,除非   专门配置为不这样做。

您可以使用简单的用户代理标头,如User-Agent:“ PHP 5.7.1”。尝试使用正确的用户代理头,rest api将按预期工作。这对于监视请求的来源很有用,也可以使您轻松地在访问统计信息日志中查找测试。

答案 1 :(得分:0)

api / v1 / files是创建文件的端点。 因此api调用看起来如下图所示:

  

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

要创建文档:

  

service_type =“ zw”

创建演示文稿

  

service_type =“ zohoshow”

您会在我们的API文档中找到大多数问题的答案。here