php 调用 Zoho WorkDrive 解压文件API 返回错误信息 {“errors“:[{“id“:“Z004“,“title“:“Failure unknown“}]}

需要在header请求头中加上 “User-Agent: xxxxxxx/2.0.0” , 即可解决

完整代码如下:

/**
 * workDrive解压文件
 * @param $resource_id      解压文件id
 * @param $tokens    token
 * @param $folder_id    解压文件指定目录id
 */
public function unzip($resource_id,$tokens,$folder_id) {
    //解压压缩文件
    $upload_url = " https://www.zohoapis.com/workdrive/api/v1/files/$folder_id/unzip";
    $header = [
        'Accept: application/vnd.api+json',
        'Authorization:Zoho-oauthtoken '.$tokens,
        "Content-Type: application/vnd.api+json",
        "User-Agent: xxxxxxx/2.0.0",
    ];
    $upload = [
        "data" => [
            "type" => "unzip",
            "attributes" => [
                "resource_id" =>"$resource_id",
                "selected_file_extraction" =>"false",
                "merge" => "no"
            ],
        ]
    ];
    $upload_data = json_encode($upload);
    return  $this->http_curl_post($upload_url,$upload_data,$header);
}

/**
 * curl post请求
 * @param $url              请求url
 * @param $post_string      参数数据
 * @param $header           header
 */
public function http_curl_post($url, $post_string,$header) {
    $ch = curl_init();    // 启动一个CURL会话
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
    curl_setopt($ch, CURLOPT_URL, $url);     // 要访问的地址
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值