我无法从fullcontact API批量请求数据。收到的响应是“无效的查询对象”,使用以下代码:
$urltopost = "https://api.fullcontact.com/v2/batch.json?apiKey=xxxxxxxxxx";
$datatopost = array (
"requests" => '["https://api.fullcontact.com/v2/person.json?email=bart@fullcontact.com","htps://api.fullcontact.com/v2/person.json?email=jigarbhatt30893@yahoo.co.in"]'
);
$header=array("content-type"=>"application/json");
$ch = curl_init ($urltopost);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);
$returndata = curl_exec ($ch);
print_r($returndata);
编写正确运行的shell执行。
curl --request POST "https://api.fullcontact.com/v2/batch.json?apiKey=xxxxxxxxxx" --data '{'requests':["https://api.fullcontact.com/v2/person.json?email=bart@fullcontact.com","https://api.fullcontact.com/v2/person.json?email=jigarbhatt30893@yahoo.co.in"]}' --header 'content-type:application/json'
但我不想从php调用shell_exec来执行此操作。我希望cURL功能起作用。出了什么问题?
答案 0 :(得分:1)
确定。所以我想我找到了自己的答案。我只需将该数组更改为字符串。而且效果很好。
$datatopost = '{"requests":["https://api.fullcontact.com/v2/person.json?email=bart@fullcontact.com","https://api.fullcontact.com/v2/person.json?email=jigarbhatt30893@yahoo.co.in"]}';
答案 1 :(得分:1)
试试这个,我测试过它并且工作正常。无需以post方法发送数据
$urltopost = "https://api.fullcontact.com/v2/person.json?apiKey=xxxxxxxxxx&email=someone@xyz.com&method=email";
$header=array("content-type"=>"application/json");
$ch = curl_init ($urltopost);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);
$returndata = curl_exec ($ch);
print_r($returndata);
答案 2 :(得分:0)
您可以尝试从请求数组中删除单引号。
"requests" => ["https://api.fullcontact.com/v2/person.json?email=bart@fullcontact.com","htps://api.fullcontact.com/v2/person.json?email=jigarbhatt30893@yahoo.co.in"]