Questo è il mio codice completo per ottenere l'ID account e il client cartella id, grazie a Carlos Duran sopra per ottenere alcuni dei miei problemi di codice elaborato:
/* iContact LIVE */
$GLOBALS['iContact_settings'] = array(
'apiUrl' => 'https://app.icontact.com',
'apiPage' => '/icp/a/',
'username' => 'username',
'password' => 'password',
'appId' => 'appId'
);
/* iContact SANDBOX */
$GLOBALS['iContact_settings'] = array(
'apiUrl' => 'https://app.sandbox.icontact.com',
'apiPage' => '/icp/a/',
'username' => 'username-beta',
'password' => 'password',
'appId' => 'appId'
);
/**/
$icontact_url = $GLOBALS['iContact_settings']['apiUrl'] . $GLOBALS['iContact_settings']['apiPage'];
$icontact_page = $GLOBALS['iContact_settings']['apiPage'];
$icontact_headers = array(
"GET ".$icontact_page." HTTP/1.0",
"Accept: text/xml",
"Content-Type: text/xml",
"API-Version: 2.2",
"API-AppId: " . $GLOBALS['iContact_settings']['appId'],
"API-Username: " . $GLOBALS['iContact_settings']['username'],
"API-Password: " . $GLOBALS['iContact_settings']['password']
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $icontact_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $icontact_headers);
$data = curl_exec($ch);
curl_close($ch);
$account_id = "";
if (($pos=strpos($data,"<accountId>"))!==false){
$account_id = substr($data, strlen("<accountId>")+$pos);
if (($pos=strpos($account_id,"<"))!==false){
$account_id = substr($account_id, 0, $pos);
}
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $icontact_url ."$account_id/c/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $icontact_headers);
$data = curl_exec($ch);
curl_close($ch);
$client_folder_id = "";
if (($pos=strpos($data,"<clientFolderId>"))!==false){
$client_folder_id = substr($data, strlen("<clientFolderId>")+$pos);
if (($pos=strpos($client_folder_id,"<"))!==false){
$client_folder_id = substr($client_folder_id, 0, $pos);
}
}
Ho appena passato a JSON , molto meglio.
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $icontact_url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handle, CURLOPT_HTTPHEADER, $icontact_headers);
$data = curl_exec($handle);
curl_close($handle);
$decoded = json_decode($data);
$account_id = $decoded->accounts[0]->accountId;
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $icontact_url ."$account_id/c/");
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handle, CURLOPT_HTTPHEADER, $icontact_headers);
$data = curl_exec($handle);
curl_close($handle);
$decoded = json_decode($data);
$client_folder_
id = $decoded->clientfolders[0]->clientFolderId;
E l'uso:
"Accept: application/json",
"Content-Type: application/json",
Invece di text/xml
sopra.
Questo ha tenuto le risposte per me. Sembra che stia usando una configurazione CURL errata. Sebbene potrebbe essere stata questa linea che mi ha salvato: "OTTIENI". $ Page. "HTTP/1.0", Tuttavia, è importante notare che le prossime due righe devono essere cambiate da "text/html" a "text/xml". – Jake