通过 php 显示 API 的过滤结果 - BatchData
P粉014293738
P粉014293738 2023-09-09 21:10:17
0
1
642

集成批处理数据 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;?>

P粉014293738
P粉014293738

全部回复(1)
P粉187677012

在尝试访问字段之前,您需要先解码 JSON

在您的 else 语句中添加此内容

$decodedResponse = json_decode($response);

我不确定您返回的确切 JSON 响应是什么,但查看示例,您可能需要使用它来获取电子邮件和电话号码,但如果没有实际响应,我无法确认这一点 (如果包含电子邮件和电话号码,请勿发布您的实际回复)

$email = $decodedResponse->results->persons[0]->emails[0]->email;
$phoneNumber = $decodedResponse->results->persons[0]->phoneNumbers[0]->number;
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板