首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >常量联系人接口,添加新联系人

常量联系人接口,添加新联系人
EN

Stack Overflow用户
提问于 2011-07-21 18:37:42
回答 1查看 1.6K关注 0票数 0

我正在尝试将新的电子邮件订阅者作为联系人添加到我的联系人列表中。但是我得到了一个404错误。以下是我的代码。有人能帮上忙吗?

代码语言:javascript
复制
$userNamePassword = $Key . '%' . $UN . ':' . $PW ;

$entry = '<entry xmlns="http://www.w3.org/2005/Atom">
<id>http://api.constantcontact.com/ws/customers/'.$UN.'/contacts/'.$SubID.'</id>
        <title type="text">Contact: '.$email.'</title>
        <updated>2008-04-25T19:29:06.096Z</updated>
        <author></author>
        <content type="application/vnd.ctct+xml">
        <Contact xmlns="http://ws.constantcontact.com/ns/1.0/"     id="http://api.constantcontact.com/ws/customers/'.$UN.'/contacts/'.$SubID.'">
        <EmailAddress>'.$email.'</EmailAddress>
        <OptInSource>ACTION_BY_CUSTOMER</OptInSource>
        <ContactLists>
        <ContactList id="http://api.constantcontact.com/ws/customers/'.$UN.'/lists/0">
        </ContactLists>
        </Contact>
        </content>
        </entry>';



       $tmpfile = tmpfile();
       fwrite($tmpfile, $entry);
       fseek($tmpfile, 0);

       // Initialize the curl session
       $request ="https://api.constantcontact.com/ws/customers/".$UN."/contacts/".$SubID;

       $session = curl_init($request);

       // Set up Digest authentication. Put your API key, and CTCT username/pwd here
       $userNamePassword = $Key . '%' . $UN . ':' . $PW ;

       curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
       curl_setopt($session, CURLOPT_USERPWD, $userNamePassword);
       curl_setopt($session, CURLOPT_INFILE, $tmpfile);
       fclose($tmpfile); // Close temp file because it no longer needed

       curl_setopt($session, CURLOPT_PUT, 1);
       curl_setopt($session, CURLOPT_INFILESIZE, strlen($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, 0);
       curl_setopt($session, CURLOPT_SSL_VERIFYPEER, 0);
       $response = curl_exec($session);
       $httpcode = curl_getinfo($session, CURLINFO_HTTP_CODE);
       curl_close($session);

         echo("httpcode error is ".$httpcode);
         if ($httpcode > 199 && $httpcode < 300){
             return 'Success';
         }else{
             return 'False';
        }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-29 14:00:44

好的,我可以通过发布来解决这个问题。即,替换了以下代码

代码语言:javascript
复制
curl_setopt($session, CURLOPT_PUT, 1);

使用以下代码

代码语言:javascript
复制
curl_setopt($session, CURLOPT_POST, 1);
curl_setopt($session, CURLOPT_POSTFIELDS, $entry);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6774712

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档