public function __construct($authType, $apiKey, $username, $param)
 {
     parent::__construct($authType, $apiKey, $username, $param);
     self::$event_cache_age = apply_filters('constant_contact_event_cache_age', apply_filters('constant_contact_cache_age', 60 * 60 * 6));
     self::$registrant_cache_age = apply_filters('constant_contact_registrant_cache_age', apply_filters('constant_contact_cache_age', 60 * 60 * 24 * 7));
 }
<?php

session_start();
require_once 'ConstantContact.php';
require_once 'config.php';
$search = false;
$action = false;
// Is there an active session with a username attached? If so we will allow them to search their contacts for an email address.
if ($DatastoreUser) {
    ?>
<html>
<body>
<?php 
    $ConstantContact = new ConstantContact("oauth2", $apikey, $username, $accessToken);
    // This is to see if a post was made
    if ($_POST) {
        if ($_POST["action"]) {
            $action = true;
        }
        if ($_POST["action"] == "logout") {
            //If the user clicks on the Log Out button then we will end the session.
            session_destroy();
            die("Logged Out, <a href='index.php'>Click Here</a> to continue.");
        } else {
            //Otherwise search the email address associated with this action.
            $search = $ConstantContact->searchContactsByEmail($_POST["searchEmailAddress"]);
        }
    }
    ?>

	<!-- this form searches for a contact by their email address -->
require_once '../config.php';
# This example is intended to be used with the OAuth 2.0 example_verification.php script that is distributed in the root folder of the Constant Contact PHP Wrapper Library.
# The full url for the example_verification.php script should be used as the Redirect URI in the settings for your API Key, which can be accessed and updated here: http://community.constantcontact.com/t5/Documentation/API-Keys/ba-p/25015.
# The example_verification.php url must also be used for the $verificationURL value in config.php file for the wrapper libary (the API Key Redirect URI, and the script use to carry out the OAuth 2.0 flow must be the same, per OAuth 2.0 standards).
# The code below checks to see if the wrapper library has a user in the datastore that has been authorized during the current session.
# If so, a form is loaded, and a request to create an email campaign is executed when the form is submitted.
# An object created from the XML in the API response is then echoed below the form, or an HTTP status code/error will be displayed.
# If the authorization is not current for the current session, an OAuth exception is throw, and a link to begin the OAuth 2.0 flow is provided.
# As authorization/authentication credentials are stored in the session by default, navigating away from your server, of failing to include session_start(); at the top of any intermediary scripts executed after authorization will cause credentials to be lost, so we recommend altering the functions in the CTCTDataStore() class or otherwise adding code of your own to save the OAuth access token securely on your server by whatever means is best suited to your needs.
?>

<h2>Simple Add/Create Campaign Example</h2>

<?php 
if ($username) {
    $ConstantContact = new ConstantContact('oauth2', $apiKey, $username, $accessToken);
    //gets first 50 contact lists, if more exist, a nextlink is returned in the $ContactLists object
    $ContactLists = $ConstantContact->getLists();
    //gets verified account email addresses which can be used as from and rely-to addresses
    $VerifiedAddresses = $ConstantContact->getVerifiedAddresses();
    $testCampaign = new Campaign();
    ?>

<form name="addCampaign" action="" method="post">
    Campaign Name: <input type="text" size="50" name="campaign_name" /><br />
    Subject Line: <input type="text" size="50" name="subject_line" /><br />
	From Name: <input type="text" size="50" name="from_name" /><br />
	<h4>From Email Address</h4>
    <div style="overflow: auto; width: 400px;">
    <?php 
    foreach ($VerifiedAddresses['addresses'] as $key => $addr) {
<h2>Add Contact Form Example</h2>
<?php 
session_start();
include_once '../ConstantContact.php';
$username = '******';
$apiKey = 'APIKEY';
$consumerSecret = 'CONSUMERSECRET';
$Datastore = new CTCTDataStore();
$DatastoreUser = $Datastore->lookupUser($username);
if ($DatastoreUser) {
    $ConstantContact = new ConstantContact('oauth', $apiKey, $DatastoreUser['username'], $consumerSecret);
    $ContactLists = $ConstantContact->getLists();
    ?>
<form name="addContact" action="" method="post">
    Email Address: <input type="text" name="email_address"><br />
    First Name: <input type="text" name="first_name"><br />
    Last Name: <input type="text" name="last_name"><br />
    <h4>Contact Lists</h4>
    <div style="border: 1px #000 solid; overflow: auto; width: 400px; height: 400px;">
    <?php 
    foreach ($ContactLists['lists'] as $list) {
        echo '<input type="checkbox" name="lists[]" value="' . $list->id . '"> ' . $list->name . '<br />';
    }
    ?>
    </div>
    <input type="submit" name="submit" value="Add Contact"><br />
</form>

<?php 
    if (isset($_POST['email_address'])) {
        $Contact = new Contact();
$search = false;
$action = false;
// Set access code
//$sessionConsumer = array ('username' => $_GET ["username"], 'access_token' => $_GET ["code"] );
$sessionConsumer = array('username' => $username, 'access_token' => $accessToken);
$Datastore = new CTCTDataStore();
$Datastore->addUser($sessionConsumer);
$username = $sessionConsumer['username'];
$DatastoreUser = $Datastore->lookupUser($username);
// Is there an active session with a username attached? If so we will allow them to search their contacts for an email address.
if ($DatastoreUser) {
    ?>
<html>
<body>
<?php 
    $ConstantContact = new ConstantContact("oauth2", $apikey, $username, $accessToken);
    // This is to see if a post was made
    if ($_POST) {
        // print_r($_POST);exit;
        if ($_POST["action"]) {
            $action = true;
        }
        if ($_POST["action"] == "logout") {
            //If the user clicks on the Log Out button then we will end the session.
            session_destroy();
            die("Logged Out, <a href='index.php'>Click Here</a> to continue.");
        } else {
            if ($_POST['SearchEmail'] == 'Search Email') {
                //Otherwise search the email address associated with this action.
                $search = $ConstantContact->searchContactsByEmail($_POST["searchEmailAddress"]);
            } else {
<h2>Contact Reporting Data Example</h2>
<?php 
session_start();
include_once '../ConstantContact.php';
$username = '******';
$apiKey = 'APIKEY';
$consumerSecret = 'CONSUMERSECRET';
$Datastore = new CTCTDataStore();
$DatastoreUser = $Datastore->lookupUser($username);
if ($DatastoreUser) {
    $emailAddress = isset($_GET['email_address']) ? $_GET['email_address'] : '';
    $ConstantContact = new ConstantContact('oauth', $apiKey, $DatastoreUser['username'], $consumerSecret);
    // Fail if the email does not exist
    ?>
        <html>
        <head><title>Contact Email History</title></head>
        <body>
        <!--- Basic form for contact event search submission --->
        <form method="get" action="">
            Email Address: <input type="text" value="<?php 
    echo $emailAddress;
    ?>
" name="email_address"><br />
            Sends <input type="radio" name="event_type" value="sends"><br />
            Clicks <input type="radio" name="event_type" value="clicks"><br />
            Opens <input type="radio" name="event_type" value="opens"><br />
            Forwards <input type="radio" name="event_type" value="forwards"><br />
            OptOuts <input type="radio" name="event_type" value="optouts"><br />
            Bounces <input type="radio" name="event_type" value="bounces"><br />
            <br /><input type="submit" value="submit" name="submit">
        </form>
function constantcontact_addContact($info, $list, $appkey, $appusername, $apptoken)
{
    if (!$apptoken || $apptoken == "") {
        return null;
    }
    if (!class_exists("ConstantContact")) {
        require_once 'CTCT-OAuth2/ConstantContact.php';
    }
    try {
        $ConstantContact = new ConstantContact("oauth2", $apikey, $appusername, $apptoken);
        $search = $ConstantContact->searchContactsByEmail($info["email"]);
        if ($search && isset($search[0])) {
            $details = $ConstantContact->getContactDetails($search[0]);
            if (isset($details->lists)) {
                $list_added = false;
                foreach ($details->lists as $l) {
                    if ($l == $list) {
                        $list_added = true;
                    }
                }
                if (!$list_added) {
                    $list_array = $details->lists;
                    array_push($list_array, $list);
                    $details->lists = $list_array;
                    $details->status = "Active";
                    $ConstantContact->updateContact($details);
                    return true;
                }
                return true;
            }
        }
    } catch (Exception $e) {
        return false;
    }
    $postFields = array();
    $postFields["emailAddress"] = $info["email"];
    $postFields["firstName"] = $info["first_name"];
    $postFields["lastName"] = $info["last_name"];
    $postFields["optInSource"] = "ACTION_BY_CONTACT";
    $postFields["lists"] = array($list);
    try {
        $ConstantContact = new ConstantContact("oauth2", $apikey, $appusername, $apptoken);
        $newContact = new Contact($postFields);
        $result = $ConstantContact->addContact($newContact);
        return true;
    } catch (Exception $e) {
        return false;
    }
    return false;
}
//session_start ();
require_once 'config.php';
require_once 'ConstantContact.php';
$search = false;
$action = false;
// Set access code
//$sessionConsumer = array ('username' => $_GET ["username"], 'access_token' => $_GET ["code"] );
$sessionConsumer = array('username' => $username, 'access_token' => $accessToken);
$Datastore = new CTCTDataStore();
$Datastore->addUser($sessionConsumer);
$username = $sessionConsumer['username'];
$DatastoreUser = $Datastore->lookupUser($username);
// Is there an active session with a username attached? If so we will allow them to search their contacts for an email address.
if ($DatastoreUser) {
    $ConstantContact = new ConstantContact("oauth2", $apikey, $username, $accessToken);
    $constantparam = $_SESSION['constantparam']['data'];
    $_SESSION['constantresult'] = "";
    // This is to see if a post was made
    if ($_SESSION['constantaction'] != "") {
        // print_r($_POST);exit;
        $action = true;
        if ($_SESSION['constantaction'] == 'Search Email') {
            //Otherwise search the email address associated with this action.
            $email = $constantparam['email'];
            $_SESSION['constantresult'] = $ConstantContact->searchContactsByEmail($email);
        } else {
            if ($_SESSION['constantaction'] == 'Add Email') {
                //Otherwise search the email address associated with this action.
                $email = $constantparam['emailAddress'];
                if ($email != "") {
date_default_timezone_set('America/New_York');
// Include the wrapper
include_once 'ConstantContact.php';
// Include the config.php file which contains your Api-key, consumer secret and
// username
include_once 'config.php';
$Datastore = new CTCTDataStore();
// $username is written to the config.php file which was entered on the
// index.php
$DatastoreUser = $Datastore->lookupUser($username);
// if the user is found then display data else give them a chance to verify
// authentication
if ($DatastoreUser) {
    // Istantiate ConstantContact Object and push in credentails for
    // authentication that would be retrieved form config.php
    $ConstantContact = new ConstantContact('oauth', $apiKey, $username, $consumerSecret);
    // Get all lists from account
    $Lists = $ConstantContact->getLists();
    // Get all verified email addresses
    $VerifiedEmailAddresses = $ConstantContact->getVerifiedAddresses();
    // parse states and countries
    $allStates = $ConstantContact->getStates();
    $allCountries = $ConstantContact->getCountries();
    // Check to see if this is a campaign that we are editing or if this is
    // adding a campaign
    if (!empty($_GET["campaignID"]) && empty($_GET["status"])) {
        // Return the campaign details by ID
        $CampaignResult = $ConstantContact->getCampaignByID($_GET["campaignID"]);
    }
    // If user is adding a new campaign, campaignName would be set to the POST
    if (isset($_POST["campaignName"])) {