对讲机Rest API搜索联系人(带PHP)



我试图通过他们的REST API检索对讲机中的联系人。我正在使用以下代码,但我得到以下错误:

代码
try {
$postdataarray['query'] = [ "field" => "email","operator" => "=","value" => $value['email']];
$postData = json_encode($postdataarray);
$postHeader = [
'Authorization:Bearer ergergergergergergergerg',
'Accept: application/json',
'Content-Type: application/json -d'
];
$curl = curl_init("https://api.intercom.io/contacts/search/");
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, FALSE);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HTTPHEADER, $postHeader);
$content = curl_exec($curl);
curl_close($curl);
echo $content;
} catch (Exception $e) {
error_log($e->getMessage());

}

误差

{"error ": [{"code": "not_found", "message": "请求的资源不存在;检查你的路径,然后再试一次。}], "type";error.list"}

更新现在我的代码看起来像这样:

try {
$postdataarray['query'] = [ "field" => "email","operator" => "=","value" => $value['email']];
$postData = json_encode($postdataarray);
$postHeader = [
'Authorization:Bearer zefzefzefzefzef',
'Accept: application/json',
'Intercom-Version: 2.3',
'Content-Type: application/json -d'
];
$curl = curl_init("https://api.intercom.io/contacts/search");
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $postHeader);
$content = curl_exec($curl);
var_dump ($content);
curl_close($curl);

} catch (Exception $e) {
error_log($e->getMessage());
}

还是不行

如果您正在发送一个post请求来检索联系人,您应该使用get方法

改变这一行:

curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");

curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");

我有同样的问题,问题是对讲机的令牌没有访问资源的权限。因此,请检查您的令牌,问题将得到解决。

相关内容

  • 没有找到相关文章

最新更新