1

我已经集成了持续联系 API。在将联系人添加到特定列表时工作正常。我创建了 5 个不同的列表。当我将联系人添加到特定列表时,如果它已经存在,我想删除此联系人表单其他列表。

请建议您是否有任何解决方案。

4

2 回答 2

1

如果您使用 PHP SDK,最简单的方法可能是访问联系人对象的列表属性并删除您不再希望用户订阅的列表对象。

您还可以像这样清除所有列表:

// Clear all lists
$contact->lists = array();

// Add the particular list you want
$contact->addList('listId');

// Update Contact
$ctct->updateContact(ACCESS_TOKEN, $contact, false);

否则,您也可以使用该deleteContactFromList($accessToken, $contact, $list)方法,但这需要更多的工作,因为它需要联系人实体和列表实体(仅 ID)。所以基本上一旦你得到了联系实体,它看起来像这样:

$contact = $ctct->getContactByEmail(ACCESS_TOKEN, $email_address)->results[0];
$listToDelete = new ContactList($listId);
$ctct->deleteContactFromList(ACCESS_TOKEN, $contact, $listToDelete);

希望有帮助!

麦克风

于 2014-02-15T00:40:09.533 回答
0

阅读此处的文档后Bulk Activities - Remove Contacts Endpoint

我采取了不同的方法。

我将布局逻辑和正确的 CC API 方法的使用,当然,您可以动态检索 list_id 并进行额外检查(即检查用户是否真的是列表的成员),但为此我正在尝试仅显示如何从列表中删除联系人,这是这里的主要思想。

开始吧。

  1. 在我的composer.json我有这个:

{ "require": { "constantcontact/constantcontact": "1.3.2" } }

由于安装了PHP 版本5.3.29的客户端服务器基础设施,我不得不使用旧的Constant Contact API

  1. 在终端导航到您的源根目录并运行composer update.

  2. 安装依赖项后,我们就可以开始了。

  3. 以我为例,我index.php会这样说:

    require_once('/vendor/autoload.php');
    use Ctct\ConstantContact;
    use Ctct\Services;
    use Ctct\Components\Contacts\Contact;
    use Ctct\Exceptions\CtctException;
    
    define("APIKEY", "YOUR_API_KEY_HERE");//Write your API key
    define("ACCESS_TOKEN", "YOUR_ACCESS_TOKEN_HERE");//Write your Access Token here
    
    $cc = new ConstantContact(APIKEY);
    $ca = new Services\ActivityService(APIKEY);
    $error = 0;
    
    try {
        $response = $cc->getContactByEmail(ACCESS_TOKEN, $email);
        if (empty($response->results)) {
            //Create new contact if needed
        } else {
            $action = "Remove contact from subscribe list";
            $contact = $response->results[0];
            try {
                $ca->addRemoveContactsFromListsActivity(
                    ACCESS_TOKEN, 
                    array($contact->email_addresses[0]->email_address), 
                    array('1894839946')//List Id from which you want the contact to be removed from
                );
            } catch (Exception $e) {
                var_dump($e->getMessage());
            }
            /*
             * The third parameter of updateContact defaults to false, but if this were set to true it would tell
             * Constant Contact that this action is being performed by the contact themselves, and gives the ability to
             * opt contacts back in and trigger Welcome/Change-of-interest emails.
             *
             * See: http://developer.constantcontact.com/docs/contacts-api/contacts-index.html#opt_in
             */
            $returnContact = $cc->updateContact(ACCESS_TOKEN, $contact, true);
        }         
    } catch (Exception $e) {
        var_dump($e->getMessage());
    }
    

希望它会帮助某人。干杯。

于 2017-06-12T09:01:15.380 回答