集成批处理数据 API 并在仅显示已过滤项目之一时出现问题。 api示例是:https://developer.batchdata.com/docs/batchdata/batchdata-v1/operations/create-a-property-skip-trace
在此示例中,我尝试仅显示电话号码或电子邮件字段。显示完整的结果,所以我知道 api 正在工作...但是,我无法显示过滤后的项目,如下所示:
<?php $email; ?> <?php echo $response->response->results->result[0]->results->persons->email;?> <?php echo $response->options->customProjection[0]->results->persons->phoneNumbers->number;?>
这是我现在拥有的完整代码:
<?php $location = $entity->getSingleFieldValue('field_site_address'); $street = $location['street']; $city = $location['city']; $state = $location['province']; $email = $response->response->results->result[0]->results->persons->email; $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://api.batchdata.com/api/v1/property/skip-trace", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => "{\n \"requests\": [\n {\n \"propertyAddress\": { \"street\": \"$street\", \"city\": \"$city\", \"state\": \"$state\" } }\n ]\n}", CURLOPT_HTTPHEADER => [ "Authorization: Bearer xxxxxx", "Content-Type: application/json" ], ]); $data = simplexml_load_string($result); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); ?> <?php if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }?> <?php $email; ?> <?php echo $response->response->results->result[0]->results->persons->email;?> <?php echo $response->options->customProjection[0]->results->persons->phoneNumbers->number;?>
在尝试访问字段之前,您需要先解码 JSON
在您的 else 语句中添加此内容
我不确定您返回的确切 JSON 响应是什么,但查看示例,您可能需要使用它来获取电子邮件和电话号码,但如果没有实际响应,我无法确认这一点 (如果包含电子邮件和电话号码,请勿发布您的实际回复)