Advertisement
Guest User

Untitled

a guest
Apr 21st, 2014
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. require "Scripts/ConstantContact/src/Ctct/autoload.php";
  2. use CtctConstantContact;
  3. use CtctComponentsContactsContact;
  4. use CtctComponentsContactsContactList;
  5. use CtctComponentsContactsEmailAddress;
  6. use CtctExceptionsCtctException;
  7.  
  8. define("APIKEY", "*** Censored Media (18+ only) ***");
  9. define("ACCESS_TOKEN", "*** Censored Media (18+ only) ***");
  10.  
  11. $cc = new ConstantContact(APIKEY);
  12.  
  13. // attempt to fetch lists in the account, catching any exceptions and printing the errors to screen
  14. $lists = $cc->getLists(ACCESS_TOKEN);
  15.  
  16. $action = "Getting Contact By Email Address";
  17. $Email = "asdf@asdf.com";
  18. $FirstName = "Asdf";
  19. $LastName = "Ghjk";
  20. // check to see if a contact with the email addess already exists in the account
  21. $response = $cc->getContactByEmail(ACCESS_TOKEN, $Email);
  22.  
  23. // create a new contact if one does not exist
  24. if (empty($response->results)) {
  25. $action = "Creating Contact";
  26.  
  27. $contact = new Contact();
  28. $contact->addEmail($Email);
  29. $contact->addList('1');
  30. $contact->first_name = $FirstName;
  31. $contact->last_name = $LastName;
  32. $returnContact = $cc->addContact(ACCESS_TOKEN, $contact);
  33.  
  34. // update the existing contact if address already existed
  35. } else {
  36. $action = "Updating Contact";
  37.  
  38. $contact = $response->results[0];
  39. $contact->addList('1');
  40. $contact->first_name = $FirstName;
  41. $contact->last_name = $LastName;
  42. $returnContact = $cc->updateContact(ACCESS_TOKEN, $contact);
  43. }
  44.  
  45. // catch any exceptions thrown during the process and print the errors to screen
  46.  
  47.  
  48. if (isset($returnContact)) {
  49. echo '<div class="container alert-success"><pre class="success-pre">';
  50. print_r($returnContact);
  51. echo '</pre></div>';
  52. }
  53. print '<p>'.$action.'</p>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement