public function makeRequest($url, $method, $body = '', $contentType = "application/atom+xml")
 {
     if ($this->authType == 'oauth') {
         $Datastore = new CTCTDataStore();
         $accessInfo = $Datastore->lookupUser($this->username);
         $accessToken = new OAuthToken((string) $accessInfo['key'], (string) $accessInfo['secret']);
         $this->accessToken = $accessToken;
         $request = OAuthRequest::from_consumer_and_token($this->consumer, $accessToken, $method, $url);
         $request->sign_request($this->signatureMethod, $this->consumer, $accessToken);
         $request->get_normalized_http_method();
         $url = $request;
     }
     $curl = curl_init();
     if ($this->authType == 'basic') {
         curl_setopt($curl, CURLOPT_USERPWD, $this->requestLogin);
         curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
     } else {
         if ($this->authType == 'oAuth2') {
             //curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
         }
     }
     curl_setopt($curl, CURLOPT_URL, $url);
     //curl_setopt($curl, CURLOPT_FAILONERROR, 0);
     curl_setopt($curl, CURLOPT_HEADER, 0);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
     if ($this->authType == 'oauth2') {
         curl_setopt($curl, CURLOPT_HTTPHEADER, array("Authorization: Bearer " . $this->access_token, "Content-Type: " . $contentType, "Content-Length: " . strlen($body), "Accept: application/atom+xml"));
     } else {
         curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: " . $contentType, "Content-Length: " . strlen($body), "Accept: application/atom+xml"));
     }
     curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
     if ($body) {
         curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
     }
     try {
         $return['xml'] = curl_exec($curl);
         $return['info'] = curl_getinfo($curl);
         $return['error'] = curl_error($curl);
         curl_close($curl);
         if (!in_array($return['info']['http_code'], array('201', '200', '204'))) {
             throw new CTCTException('Constant Contact HTTP Request Exception: ' . $return['xml']);
         } else {
             $return = $return;
         }
     } catch (CTCTException $e) {
         $e->generateError();
     }
     return $return;
 }
Exemplo n.º 2
0
 * 

 * This config.php file is intended to hold you Constant Contact

 * Credentials.  There are two different ways to implement the 

 * oAuth2 authentication from with in this library.

 * 

 *  The first way is from with in session.  This information is not

 *  stored anywhere locally, other than that of the clients browser.

 *  The following code breaks apart the session into the actual 

 *  credentials.  The information could also be sent to a Database

 *  or handled directly as you will see below.

 * 

 */
$Datastore = new CTCTDataStore();
if (isset($_SESSION['users'])) {
    foreach ($_SESSION['users'] as $user) {
        if ($user['username'] != false) {
            $DatastoreUser = $Datastore->lookupUser($user['username']);
            $username = $user['username'];
            $accessToken = $user['access_token'];
        }
<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();