对Zoho API CRM没有任何回应

时间:2013-11-24 15:52:34

标签: php zoho

我正在尝试使用getSearchRecordsByPDC方法,可在此处找到https://www.zoho.com/crm/help/api/getsearchrecordsbypdc.html#Request_URL

我有这段代码:

private $token = '1234567890abcdefg';
public $responseType = 'xml';

 public function getSearchRecordsByPDC($searchValue,$searchColumn='email')
 {
 $url = "https://crm.zoho.com/crm/private/".$this->responseType."/Leads/getSearchRecordsByPDC?newFormat=1&authtoken=".$this->token."&scope=crmapi&selectColumns=Leads(First Name,Lead Source,Phone,Mobile,Website,Lead Status,Description,Last Name,Website,Email,Lead Owner)&searchColumn=$searchColumn&searchValue=$searchValue";

 $result = $this->curlRequest($url);
 return $result;
 }

 public function curlRequest($url)
 {
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 $output = curl_exec($ch);
 curl_close($ch);
 return $output;
 }

$data = $zoho->getSearchRecordsByPDC('my_email@gmail.com');
print_r($data);

我刚刚发布了一些我的代码片段,看起来不是很长。

运行此代码时。我没有得到任何响应,甚至是错误消息或者无论如何,我得到的是空白响应,没有xml响应或者其他什么。但是,当我尝试将$url变量输出复制并粘贴到我的Web浏览器中时,我得到了响应,并且这些响应是有效的。

这有什么问题?对你的帮助表示感谢!谢谢!

1 个答案:

答案 0 :(得分:0)

看起来你正在混淆OOP和程序代码。试试这个:

class Zoho {
    private $token = '1234567890abcdefg';
    public $responseType = 'xml';

    public function getSearchRecordsByPDC($searchValue,$searchColumn='email')
    {
        $url = "https://crm.zoho.com/crm/private/".$this->responseType."/Leads/getSearchRecordsByPDC?newFormat=1&authtoken=".$this->token."&scope=crmapi&selectColumns=Leads(First Name,Lead Source,Phone,Mobile,Website,Lead Status,Description,Last Name,Website,Email,Lead Owner)&searchColumn=$searchColumn&searchValue=$searchValue";

        $result = $this->curlRequest($url);
        return $result;
    }

    public function curlRequest($url)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }
}

$zoho = new Zoho;
$data = $zoho->getSearchRecordsByPDC('my_email@gmail.com');
print_r($data);