CkPhp Requires Chilkat v11.0.0+
CkPhp
Constant Contact V3: Read every page of list members
See more Constant Contact Examples
Filter the contacts collection with lists and a list ID. To query multiple lists together, supply their comma-separated IDs. Follow the returned cursor links and report the total after the last page. The default contacts query excludes deleted records. A list member can still have unsubscribed email permission. Authorize the app first and use the same credential store.
Constant Contact developer guide
Chilkat CkPhp Downloads
<?php
include("chilkat.php");
$success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
$vault = new CkSecrets();
$vault->put_Location('local_manager');
$vault->put_AutoSplit(true);
$entry = new CkJsonObject();
$entry->UpdateString('appName','ConstantContactV3');
$entry->UpdateString('service','OAuth2');
$entry->UpdateString('username','my-account');
$tokens = new CkJsonObject();
$loaded = $vault->GetSecretJson($entry,$tokens);
if ($loaded != true) {
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 CkHttp();
$http->put_RequireSslCertVerify(true);
$http->put_AuthToken($tokens->stringOf('access_token'));
$resp = new CkHttpResponse();
$http->SetUrlVar('list','LIST_ID');
$url = new CkStringBuilder();
$url->Append('https://api.cc.email/v3/contacts?lists={$list}&limit=50');
$page = new CkJsonObject();
$total = 0;
while (($url->get_Length() > 0)) {
$success = $http->HttpNoBody('GET',$url->getAsString(),$resp);
if (($success != true) or ($resp->get_StatusCode() != 200)) {
print 'Expected HTTP 200. Received ' . $resp->get_StatusCode() . "\n";
if ($resp->get_StatusCode() == 401) {
print 'Refresh the saved access token or authorize again.' . "\n";
}
exit;
}
$success = $page->Load($resp->bodyStr());
$count = $page->SizeOfArray('contacts');
if (($success != true) or ($count < 0)) {
print 'Expected a page of contacts.' . "\n";
exit;
}
$i = 0;
while (($i < $count)) {
$page->put_I($i);
print $page->stringOf('contacts[i].contact_id') . ' ' . $page->stringOf('contacts[i].email_address.address') . "\n";
$i = $i + 1;
}
$total = $total + $count;
$url->Clear();
if ($page->JsonTypeOf('_links.next.href') == 1) {
$url->Append($page->stringOf('_links.next.href'));
// The documented cursor link is relative to api.cc.email.
if ($url->StartsWith('/v3/contacts?',true) != true) {
print 'Unexpected pagination link. Stopped before following it.' . "\n";
exit;
}
$url->Prepend('https://api.cc.email');
}
}
print 'List members read: ' . $total . "\n";
?>