2013-07-05 160 views
0

我無法從fullcontact API批量請求數據。收到的響應是使用以下代碼的「無效查詢對象」:如何在PHP中使用FullContactAPI的批量請求POST請求?

$urltopost = "https://api.fullcontact.com/v2/batch.json?apiKey=xxxxxxxxxx"; 
$datatopost = array (
    "requests" => '["https://api.fullcontact.com/v2/[email protected]","htps://api.fullcontact.com/v2/[email protected]"]' 
); 
$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/[email protected]","https://api.fullcontact.com/v2/[email protected]"]}' --header 'content-type:application/json' 

但我不想從PHP調用shell_exec來做到這一點。我想讓cURL函數起作用。出了什麼問題?

+0

感謝Danny的編輯幫助。一段時間以來,我對這個問題非常嚴重。 –

+0

以下是提供Post請求示例的鏈接。 http://www.fullcontact.com/developer/docs/batch/ –

回答

1

好的。所以我想我找到了自己的答案。我只需要將該數組更改爲字符串。它的工作完美。

$datatopost = '{"requests":["https://api.fullcontact.com/v2/[email protected]","https://api.fullcontact.com/v2/[email protected]"]}'; 
+0

它沒有工作 –

1

試試這個,我已經測試過它並且工作正常。無需發送後數據的方法

$urltopost = "https://api.fullcontact.com/v2/person.json?apiKey=xxxxxxxxxx&[email protected]&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);