PHP ActiveX Requires Chilkat v11.0.0+
PHP ActiveX
Constant Contact V3: Find a contact by email address
See more Constant Contact Examples
Look up an exact email address across contact states, including deleted contacts. Pass the address as a query parameter so a literal plus sign survives URL encoding. Read the stored contact ID, email permission, and deletion marker. An empty contacts array means no match. Authorize the app first and use the same credential store.
Constant Contact developer guide
Chilkat PHP ActiveX Downloads
<?php
$success = 0;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
$vault = new COM("Chilkat.Secrets");
$vault->Location = 'local_manager';
$vault->AutoSplit = 1;
$entry = new COM("Chilkat.JsonObject");
$entry->UpdateString('appName','ConstantContactV3');
$entry->UpdateString('service','OAuth2');
$entry->UpdateString('username','my-account');
$tokens = new COM("Chilkat.JsonObject");
$loaded = $vault->GetSecretJson($entry,$tokens);
if ($loaded != 1) {
print 'Run the desktop authorization example using this account and store.' . "\n";
exit;
}
if ($tokens->JsonTypeOf('access_token') != 1) {
print 'The saved authorization has no access token.' . "\n";
exit;
}
$http = new COM("Chilkat.Http");
$http->RequireSslCertVerify = 1;
$http->AuthToken = $tokens->stringOf('access_token');
$resp = new COM("Chilkat.HttpResponse");
$query = new COM("Chilkat.HttpRequest");
$query->HttpVerb = 'GET';
$query->AddParam('email','reader+newsletter@example.com');
$query->AddParam('status','all');
$success = $http->HttpReq('https://api.cc.email/v3/contacts',$query,$resp);
if (($success != 1) or ($resp->StatusCode != 200)) {
print 'Expected HTTP 200. Received ' . $resp->StatusCode . "\n";
if ($resp->StatusCode == 401) {
print 'Refresh the saved access token or authorize again.' . "\n";
}
exit;
}
$reply = new COM("Chilkat.JsonObject");
$success = $reply->Load($resp->BodyStr);
if ($success != 1) {
print 'Expected a JSON response.' . "\n";
exit;
}
$count = $reply->SizeOfArray('contacts');
if ($count < 0) {
print 'The reply contained no contacts array.' . "\n";
exit;
}
if ($count == 0) {
print 'No contact has that email address.' . "\n";
exit;
}
$i = 0;
while (($i < $count)) {
$reply->I = $i;
print 'Contact ID: ' . $reply->stringOf('contacts[i].contact_id') . "\n";
print 'Email permission: ' . $reply->stringOf('contacts[i].email_address.permission_to_send') . "\n";
if ($reply->JsonTypeOf('contacts[i].deleted_at') == 1) {
print 'Deleted at: ' . $reply->stringOf('contacts[i].deleted_at') . "\n";
}
$i = $i + 1;
}
?>