Hi,
You should be able to make a simple request to our servers like you showed. What error are you receiving when you make the call? Regardless, you don't have to generate an access token to use the PHP library, and I do recommend using the library since it handles curl and authentication. You can use the wrapper with basic authentication, requiring only your username, password, and API Key, which you can hard code into config.php (keeping other lines for access token, etc, commented out).
Here is my sample code for adding or updating a contact using the PHP wrapper.
<?php
session_start ();
require_once 'ConstantContact.php';
require_once 'config.php';
//$ConstantContact = new ConstantContact("oauth2", $apiKey, $username, $accessToken); //OR
ConstantContact = new ConstantContact("basic", $apiKey, $username, $password);
//Supply your credentials--API Key and other details--in config.php
// Get potential contact lists
$lists = $ConstantContact->getLists();
// Lists are returned in multidimentional arrays 0 being the list, and 1 being the next50
// Email address here is used for testing purposes
$emailAddress = "test_12132012@example.com";
// Search for our new Email address
$search = $ConstantContact->searchContactsByEmail($emailAddress);
//Debugging
echo '<pre>';
print_r($ConstantContact);
echo '</pre>';
echo $emailAddress . "<br>";
// If the search didnt return a contact object
if($search == false)
{
// Create a new Contact Object to store data into
$contactObj = new Contact();
// Adding multiple lists to this new Contact Object
$contactObj->lists = array($lists['lists'][0]->id, $lists['lists'][1]->id);
// Set the email address
$contactObj->emailAddress = $emailAddress;
//Set the opt in source
$contactObj->optInSource = "ACTION_BY_CONTACT";
// Create the Contact and DONE
$Contact = $ConstantContact->addContact($contactObj);
echo ("Contact added.");
} // Otherwise we update our existing contact
else
{
// Gather data from our previous search and store it into a data type
$contactObj = $ConstantContact->getContactDetails($search[0]);
// We need to get the old list and add a new list to it as
// this request requires a PUT and will remove the lists
// as they are stored in an array
array_push($contactObj->lists, $lists['lists'][1]->id );
//Set the opt in value
$contactObj->optInSource = "ACTION_BY_CONTACT";
// Update the contact and DONE
$UpdateContact = $ConstantContact->updateContact($contactObj);
echo ("Contact updated.");
}
?>
Best Regards,
Shannon W.
API Support Specialist
... View more