CkJava Requires Chilkat v11.0.0+
CkJava
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 CkJava Downloads
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
boolean success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
CkSecrets vault = new CkSecrets();
vault.put_Location("local_manager");
vault.put_AutoSplit(true);
CkJsonObject entry = new CkJsonObject();
entry.UpdateString("appName","ConstantContactV3");
entry.UpdateString("service","OAuth2");
entry.UpdateString("username","my-account");
CkJsonObject tokens = new CkJsonObject();
boolean loaded = vault.GetSecretJson(entry,tokens);
if (loaded != true) {
System.out.println("Run the desktop authorization example using this account and store.");
return;
}
if (tokens.JsonTypeOf("access_token") != 1) {
System.out.println("The saved authorization has no access token.");
return;
}
CkHttp http = new CkHttp();
http.put_RequireSslCertVerify(true);
http.put_AuthToken(tokens.stringOf("access_token"));
CkHttpResponse resp = new CkHttpResponse();
CkHttpRequest query = new CkHttpRequest();
query.put_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 != true) || (resp.get_StatusCode() != 200)) {
System.out.println("Expected HTTP 200. Received " + resp.get_StatusCode());
if (resp.get_StatusCode() == 401) {
System.out.println("Refresh the saved access token or authorize again.");
}
return;
}
CkJsonObject reply = new CkJsonObject();
success = reply.Load(resp.bodyStr());
if (success != true) {
System.out.println("Expected a JSON response.");
return;
}
int count = reply.SizeOfArray("contacts");
if (count < 0) {
System.out.println("The reply contained no contacts array.");
return;
}
if (count == 0) {
System.out.println("No contact has that email address.");
return;
}
int i = 0;
while ((i < count)) {
reply.put_I(i);
System.out.println("Contact ID: " + reply.stringOf("contacts[i].contact_id"));
System.out.println("Email permission: " + reply.stringOf("contacts[i].email_address.permission_to_send"));
if (reply.JsonTypeOf("contacts[i].deleted_at") == 1) {
System.out.println("Deleted at: " + reply.stringOf("contacts[i].deleted_at"));
}
i = i+1;
}
}
}