如何使用不断接触API? [英] How to use Constant Contact API?

查看:151
本文介绍了如何使用不断接触API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用的不断接触的API,并想用PHP,而用户注册到网站将用户的电子邮件。

请,如果任何帮助回复。

先谢谢了。


解决方案

  //填写你的Constant Contact的登录名和API密钥
$ ccuser ='USERNAME_HERE';
$ ccpass ='​​PASS_HERE';
$ cckey ='APIKEY_HERE';//填写这些值
$的firstName =;
$的lastName =;
$ EMAILADDR =;
$邮编=;//重新presents联系人列表识别号码
$ contactListId = INTEGER_OR_ARRAY_OF_INTEGERS_HERE;
$ contactListId =(!is_array($ contactListId))?阵列($ contactListId):$ contactListId;$ =后新的SimpleXMLElement('<输入>< /进入>');
$后>的addAttribute('的xmlns','http://www.w3.org/2005/Atom');$标题= $&后GT;的addChild(标题,);
$标题 - >的addAttribute('型','文字');$&后GT;的addChild('更新',日期('C'));
$&后GT;的addChild(作者,);
$&后GT;的addChild('身份证','数据:,无');$总结= $&后GT;的addChild(摘要,联系我们);
$总结 - >的addAttribute('型','文字');$内容= $&后GT;的addChild(内容);
$内容 - >的addAttribute('型','应用程序/ vnd.ctct + XML');$触点= $内容 - >的addChild('联系');
$接触式>的addAttribute('的xmlns','http://ws.constantcontact.com/ns/1.0/');$接触式>的addChild('EmailAddress的',$ EMAILADDR);
$接触式>的addChild('名字',$的firstName);
$接触式>的addChild('姓氏',$ lastName的);
$接触式>的addChild('邮政code',$ ZIP);
$接触式>的addChild('OptInSource','ACTION_BY_CUSTOMER');$ contactlists = $接触式>的addChild('ContactLists');//通过每个定义的联系人列表循环
的foreach($ contactListId AS $ listId){
    $ contactlist = $ contactlists->的addChild('ContactList');
    $ contactlist->的addAttribute('ID','http://api.constantcontact.com/ws/customers/'$ ccuser'/列表/'$ listId);
}$ posturl =htt​​ps://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,$后> asXML());
curl_setopt($ CH,CURLOPT_HTTPHEADER,阵列(内容类型:应用程序/原子+ XML));
curl_setopt($ CH,CURLOPT_HEADER,FALSE); //不要返回头
curl_setopt($ CH,CURLOPT_RETURNTRANSFER,0); //如果将此设置为0,它会带你到一个页面的HTTP响应$响应= curl_exec($ CH);curl_close($ CH);//成功返回真,对虚假错误
回报(is_numeric($响应)!);

I want to use API of the constant contact and want to insert user email using PHP while user register to the site.

please reply if any help.

Thanks in advance.

解决方案

// 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));

这篇关于如何使用不断接触API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆