4
A
回答
10
// fill in your Constant Contact login and API key
$ccuser = 'USERNAME_HERE';
$ccpass = 'PASS_HERE';
$cckey = 'APIKEY_HERE';
// fill in these values
$firstName = "";
$lastName = "";
$emailAddr = "";
$zip = "";
// represents the contact list identification number(s)
$contactListId = INTEGER_OR_ARRAY_OF_INTEGERS_HERE;
$contactListId = (!is_array($contactListId)) ? array($contactListId) : $contactListId;
$post = new SimpleXMLElement('<entry></entry>');
$post->addAttribute('xmlns', 'http://www.w3.org/2005/Atom');
$title = $post->addChild('title', "");
$title->addAttribute('type', 'text');
$post->addChild('updated', date('c'));
$post->addChild('author', "");
$post->addChild('id', 'data:,none');
$summary = $post->addChild('summary', 'Contact');
$summary->addAttribute('type', 'text');
$content = $post->addChild('content');
$content->addAttribute('type', 'application/vnd.ctct+xml');
$contact = $content->addChild('Contact');
$contact->addAttribute('xmlns', 'http://ws.constantcontact.com/ns/1.0/');
$contact->addChild('EmailAddress', $emailAddr);
$contact->addChild('FirstName', $firstName);
$contact->addChild('LastName', $lastName);
$contact->addChild('PostalCode', $zip);
$contact->addChild('OptInSource', 'ACTION_BY_CUSTOMER');
$contactlists = $contact->addChild('ContactLists');
// loop through each of the defined contact lists
foreach($contactListId AS $listId) {
$contactlist = $contactlists->addChild('ContactList');
$contactlist->addAttribute('id', 'http://api.constantcontact.com/ws/customers/' . $ccuser . '/lists/' . $listId);
}
$posturl = "https://api.constantcontact.com/ws/customers/{$ccuser}/contacts";
$authstr = $cckey . '%' . $ccuser . ':' . $ccpass;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $posturl);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $authstr);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/atom+xml"));
curl_setopt($ch, CURLOPT_HEADER, false); // Do not return headers
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); // If you set this to 0, it will take you to a page with the http response
$response = curl_exec($ch);
curl_close($ch);
// returns true on success, false on error
return (!is_numeric($response));
+0
不適合我,總是返回false – GusDeCooL 2011-07-26 22:32:31
1
如果你不能得到這個工作,你可能需要添加此curl_setopt:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
2
ConstantContact的開發商紛紛推出PHP庫來處理這類任務。
以下版本適用於較舊的PHP版本(5.2或更低版本)。從此處下載代碼:https://github.com/constantcontact/ctct_php_library
以下是在訂閱者常用聯繫人列表中添加訂閱者電子郵件的示例。
下載上述庫後,使用以下代碼在常量聯繫人列表中添加電子郵件。
session_start();
include_once('ConstantContact.php'); // Set path accordingly
$username = 'YOUR_CONSTANT_CONTACT_USER_NAME';
$apiKey = 'YOUR_API_KEY';
$password = 'YOUR_CONSTANT_CONTACT_PASSWORD';
$ConstantContact = new Constantcontact("basic", $apiKey, $username, $password);
$emailAddress = "[email protected]";
// Search for our new Email address
$search = $ConstantContact->searchContactsByEmail($emailAddress);
// If the search did not return a contact object
if($search == false){
$Contact = new Contact();
$Contact->emailAddress = $emailAddress;
//$Contact->firstName = $firstName;
//$Contact->lastName = $lastName;
// represents the contact list identification link(s)
$contactList = LINK_OR_ARRAY_OF_LINKS_HERE;
// For example,
// "http://api.constantcontact.com/ws/customers/USER_NAME/lists/14";
$Contact->lists = (!is_array($contactList)) ? array($contactList) : $contactList;
$NewContact = $ConstantContact->addContact($Contact);
if($NewContact){
echo "Contact Added. This is your newly created contact's information<br /><pre>";
print_r($NewContact);
echo "</pre>";
}
} else {
echo "Contact already exist.";
}
注:最新版本可以在以下網址給出GitHub的鏈接中找到:http://developer.constantcontact.com/libraries/sample-code.html 但我不知道,如果上面的示例代碼,是用新庫與否。
相關問題
- 1. 常量聯繫API簡單形式
- 2. 常量聯繫API,在python中添加一個新聯繫人
- 3. 常量聯繫API - (403)禁止添加新聯繫人
- 4. 常量聯繫API,添加新聯繫人
- 5. 常量聯繫utility.searchbyemail()
- 6. 常量聯繫人 - 更新聯繫人
- 7. 如何使用常量聯繫人數據庫
- 8. 常量聯繫API - 從UI中獲取廣告系列ID
- 9. 常量聯繫人ID
- 10. 如何在桌面應用程序中集成常量聯繫人API?
- 11. Google聯繫人API:如何獲取google api聯繫人圖片?
- 12. 如何聯繫以討論API調用?
- 13. 如何調用Android聯繫人API
- 14. 使用聯繫人與谷歌聯繫人同步聯繫人javascript api
- 15. 創建大量聯繫人Google聯繫人API V3
- 16. 常量聯繫C#Wrapper - 將聯繫人添加到列表
- 17. 預先填寫的聯繫表格(常量聯繫人和WordPress)
- 18. 使用雅虎聯繫人API獲取雅虎聯繫人
- 19. 如何使用Yahoo!在iOS應用程序中聯繫API?
- 20. Android聯繫API
- 21. Yahoo聯繫API
- 22. 如何在php中使用常量聯繫人發送交易電子郵件
- 23. 從常用聯繫人的特定列表中刪除聯繫人API
- 24. 如何僅通過聯繫人API取回特定聯繫人
- 25. 如何從谷歌聯繫人API獲取谷歌聯繫人?
- 26. 使用Google People API確定聯繫人的數量
- 27. 未初始化的常量聯繫:: ClientsController
- 28. Ruby OAuth Nightmare:使用聯繫人API
- 29. 使用oauth api獲取aol聯繫人
- 30. 使用谷歌聯繫人API
請澄清你的問題。我沒有得到你想要做的事情;) – 2009-09-23 07:03:38
Constant Contact爲時事通訊管理提供服務。 我想在註冊該網站時將用戶添加到常用聯繫人數據庫中。 意味着他們在註冊網站時會自動添加到新聞組。 感謝您對我的問題感興趣。 – Avinash 2009-09-29 06:39:37