gpt4 book ai didi

php - 使用 CURL 从 CRM API 中提取数据抛出错误

转载 作者:行者123 更新时间:2023-12-04 03:39:35 25 4
gpt4 key购买 nike

我必须与我们公司正在使用的 CRM Snapforce CRM 集成。我只是想使用他们在文档中的示例代码来提取数据,但它返回了一个错误:

Error: Cannot create object

我复制的示例脚本直接来自他们的api documentation .

到目前为止,这是我的脚本,我几乎完全按照他们的原样复制了它。

$url = 'https://crm.snapforce.com/vintage/sf_receive_request.inc.php';
$curl = curl_init($url);
$fetchRecords = "format=xml&api_user=$api_user&api_key=$api_key&module=Leads&status=Active&method=fetchRecords";
curl_setopt($curl, CURLOPT_FAILONERROR, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 5);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POST_FIELDS, $fetchRecords);
$r = curl_exec($curl);
curl_close($curl);
libxml_use_internal_errors(true);
$xml = simplexml_load_string($r) or die("Error: Cannot create object");
foreach ($xml as $xml1) {
echo $xml1->lead_id."\n";
echo $xml1->type."\n";
echo $xml1->website."\n";
echo $xml1->contact_first."\n";
}

这是我尝试循环遍历对象的方式的问题,还是我可能缺少带有 CURL 的 setopt?任何建议将不胜感激。

最佳答案

CURLOPT_POST_FIELDS 不是有效选项,它是 CURLOPT_POSTFIELDS。

关于php - 使用 CURL 从 CRM API 中提取数据抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66307034/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com