duanjiebian6712 2016-12-13 12:37
浏览 50

公司股票的Linkedin API返回false

Linkedin API Company Share return false. There is no error data. Same code working perfect in my local. False returns only in server. Redirect url added properly in linkedin app.

This is the code which uses access token and make the share update request.

public function postToCompany($company_id,$content=array()){
    $params['url'] = 'https://api.linkedin.com/v1/companies/'.$company_id.'/shares';
    $params['method']='post';
    $params['headers']['Content-Type']='application/json';
    $params['headers']['x-li-format']='json';
    $json = array('comment'=>$content['comment'] , 'visibility'=> array('code'=>'anyone'));

    if(is_array($content) AND count($content)>0) {
        // If the content of the post is specified (e.g., a link to a website), add it here
        $json['content'] = array(); 
        if(isset($content['content']['title'])){
            $json['content']['title'] = $content['content']['title'];
        }
        if(isset($content['content']['submitted-url'])){
            $json['content']['submitted-url'] = $content['content']['submitted-url'];
        }
        if(isset($content['content']['submitted-image-url'])){
            $json['content']['submitted-image-url'] = $content['content']['submitted-image-url'];
        }
        if(isset($content['content']['description'])){
            $json['content']['description'] = $content['content']['description'];
        }
    }
    $params['args']=json_encode($json);
    $result =  $this->makeRequest($params);
    return json_decode($result,true);
}

protected function makeRequest($params=array()){
    $this->error = '';
    $method=isset($params['method'])?$params['method']:'get';
    $headers = isset($params['headers'])?$params['headers']:array();
    $args = isset($params['args'])?$params['args']:'';
    $url = $params['url'];

    $url.='?';
    if($this->access_token){
        $url .= $this->access_token_name.'='.$this->access_token;
    }

    if($method=='get'){
        $url.='&'.$this->preparePostFields($args); 
    }
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
    if($method=='post'){
        curl_setopt($ch, CURLOPT_POST, TRUE); 
        curl_setopt($ch, CURLOPT_POSTFIELDS, $this->preparePostFields($args)); 
    }elseif($method=='delete'){
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
    }elseif($method=='put'){
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
    }
    if(is_array($headers) && !empty($headers)){
        $headers_arr=array();
        foreach($headers as $k=>$v){
            $headers_arr[]=$k.': '.$v;
        }
        curl_setopt($ch,CURLOPT_HTTPHEADER,$headers_arr);
    }
    $result = curl_exec($ch);

    curl_close($ch);
    return $result;
}

protected function preparePostFields($array) {
    if(is_array($array)){
        $params = array();
        foreach ($array as $key => $value) {
            $params[] = $key . '=' . urlencode($value);
        }
        return implode('&', $params);
    }else{
        return $array;
    }
}
  • 写回答

1条回答 默认 最新

  • douzhang2680 2016-12-14 05:48
    关注

    Linkedin was looking for ssl certificate. So i added the code for disabling ssl check.

    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大