I'm using the php add contact code.
I want to simply add a user to list of my cleints.
My clients have constant contact.
It's a shame that CC does nto simply allow a curl post to instanly add a contact.
My problem is, with the php add contact I've inputted my information but I get an error:
"OAuth Exception: Username raverandi not found in datastore Click here to authorize"
Now, I don't know what to put in the user name field.
Is it my cleints username , or mine? If it's mine, then were do I place my cleints user name.
I don't have the time to dedicated the arragont reason on why CC does not opperate like other networks. I'm considering dropping CC as an option unless I find out how to do this. I've looked everywhere but can't find it.
Which PHP tool are you using to add the contact (Sample Contact Forms, PHP Wrapper Library, or CCSFG)? Depending on which option you are using, we can definitely provide insight as to what is needed, and why that error is coming up.
I got it working. Thank god, I was getting so frustrated last night. :smileyhappy:
But here's the things, heres the code im using:
$emailaddress = "email@example.com";
/////////// REGISTER EMAIL WITH CONSTANT CONTACT ///////////////////
$UN = "";
$PW = "";
$Key = "";
$entry = '<entry xmlns="http://www.w3.org/2005/Atom">
<title type="text"> </title>
<updated>' . date('c') . '</updated>
<EmailAddress>' . $emailaddress . '</EmailAddress>
<ContactList id="http://api.constantcontact.com/ws/customers/' . $UN . '/lists/1" />
// Initialize the cURL session
$request ="https://api.constantcontact.com/ws/customers/" . $UN . "/contacts";
$session = curl_init($request);
// Set up digest authentication
$userNamePassword = $Key . '%' . $UN . ':' . $PW ;
// Set cURL options
curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($session, CURLOPT_USERPWD, $userNamePassword);
curl_setopt($session, CURLOPT_POST, 1);
curl_setopt($session, CURLOPT_POSTFIELDS , $entry);
curl_setopt($session, CURLOPT_HTTPHEADER, Array("Content-Type:application/atom+xml"));
curl_setopt($session, CURLOPT_HEADER, false); // Do not return headers
curl_setopt($session, CURLOPT_RETURNTRANSFER, 1); // If you set this to 0, it will take you to a page with the http response
// Execute cURL session and close it
$response = curl_exec($session);
How do I make it for my clients?
Because I don't want to ask them for their password, I see that I can do Oath 2 But where and how could I do that?
Is there a field I could put the auth token or?
OAuth 2 is probably the simplest way, as you surmised. It can be accomplished in just a few steps using the CTCTOauth2 class in the Authentication.php file of our PHP wrapper library, or by using another self-contained approach (like this open-source example). The trick is then to store the access token locally, or to hard code that into your script that makes your script above.
To use the access token, you can then either add the following header to your curl request:
or, you can append it as a parameter to the request uri:
(where "the_token" should obviously be replaced with the actual token).
I hope this will help you get this up and running. Let us know if you run into any snags or have additional question.