Android™ Requires Chilkat v11.0.0+
Android™
Constant Contact V3: Send a test email to reviewers
See more Constant Contact Examples
Read the primary activity ID from newsletter-selection.json. Replace the two reviewer addresses and send a preview with a personal note. Only the specified reviewers receive it. The request leaves the campaign schedule and contact lists alone.
Use up to five addresses per request. Each recipient counts toward the 50 daily test emails. Contact personalization and custom field values are not expanded in test messages. Success is HTTP 204 with an empty body.
Authorize the application using the same account and credential store.
Constant Contact developer guide
Chilkat Android™ Downloads
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
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) {
Log.i(TAG, "Run the desktop authorization example using this account and store.");
return;
}
if (tokens.JsonTypeOf("access_token") != 1) {
Log.i(TAG, "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();
// Use the selection file from the draft or campaign lookup example for this account.
CkJsonObject selection = new CkJsonObject();
success = selection.LoadFile("newsletter-selection.json");
String activityId = selection.stringOf("campaign_activity_id");
if ((success != true) or (activityId == "")) {
Log.i(TAG, "Select a campaign and save its primary activity ID first.");
return;
}
http.SetUrlVar("activity",activityId);
CkJsonObject testMail = new CkJsonObject();
testMail.UpdateString("email_addresses[0]","editor@example.com");
testMail.UpdateString("email_addresses[1]","reviewer@example.com");
testMail.UpdateString("personal_message","Please check the workshop dates and the registration link.");
success = http.HttpJson("POST","https://api.cc.email/v3/emails/activities/{$activity}/tests",testMail,"application/json",resp);
if (resp.get_StatusCode() == 429) {
Log.i(TAG, "HTTP 429: Test-send limit reached. Each reviewer counts toward the daily allowance.");
return;
}
if ((success != true) and (resp.get_StatusCode() <= 0)) {
Log.i(TAG, "Send reviewer test: HTTP request failed.");
return;
}
if ((success != true) or (resp.get_StatusCode() != 204)) {
Log.i(TAG, "Send reviewer test: HTTP " + String.valueOf(resp.get_StatusCode()) + " " + resp.bodyStr());
return;
}
Log.i(TAG, "Test email accepted for the two reviewer addresses.");
}
static {
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}