Version 0.0.1 by Evan Coury
This is a complete re-write of the Constant Contact PHP API library.
- PHP 5.1.3+ w/ cURL
- A valid Constant Contact account. You can register for a free trial with no credit card at http://www.constantcontact.com/.
- A valid API Key for your Constant Contact account, obtained from http://developer.constantcontact.com/.
- 100% PHPUnit test coverage
- Proper PSR-0 compliance
- Code style checking
- Travis-CI integration
If you are using an older version of this library in your application, the old code is still available under the ./legacy/
directory.
Authentication with Constant Contact is supported via OAuth2.
If you haven't already, you can register your client application for OAuth / API access here.
<?php
require_once 'ctct_php_library/init_autoloader.php';
$consumerKey = 'YOURCONSUMERKEY'; // Referred to by Constant Contact as "client_id" or "API key"
$consumerSecret = 'YOURCONSUMERSECRET'; // Referred to by Constant Contact as "client secret"
$returnUrl = 'https://yoururl/returnurl'; // Must match the URL you registered with Constant Contact
$client = new Ctct_ApiClient($consumerKey, $consumerSecret);
if (empty($_COOKIE['ctctAccessToken'])) {
if (empty($_GET['code'] || empty($_GET['username'])) {
$redirectUrl = $client->getAuthorizeUrl($returnUrl);
header('Location: ' . $redirectUrl);
exit();
}
try {
$accessToken = $client->getAccessToken($_GET['code'], $returnUrl);
} catch (Ctct_Exception $e) {
echo 'Error: ' . $e->getMessage();
exit();
}
setcookie('ctctAccessToken', $accessToken);
setcookie('ctctUsername', $_GET['username']);
}
?>
You are now authenticated with Constant Contact as <?php echo $_COOKIE['ctctUsername']; ?>!