0

我在使用 Mailchimp API 批量取消标记订阅者时遇到问题。

在文档中https://mailchimp.com/developer/guides/how-to-use-tags/#Tag_multiple_contacts_in_bulk 是示例:

{
    "members_to_remove": [
        "john.smith@example.com",
        "brad.hudson@example.com"
        ]
}

您可以在下面看到我的 PHP 代码,其中我使用 $methode 变量给出值members_to_remove并且 $email 值是一个包含电子邮件地址的数组。

但该脚本仅向订阅添加大量标签,而不是删除。

我错了什么?

public function tag_mailchimp($list_id, $email, $tag, $method) {

    $authToken = 'HERE MY KEY';
    // The data to send to the API


    $postData = array(
        $method => $email
    );

    // Setup cURL
    $ch = curl_init('https://us2.api.mailchimp.com/3.0/lists/'.$list_id.'/segments/'.$tag);

    curl_setopt_array($ch, array(
        CURLOPT_POST => TRUE,
        CURLOPT_RETURNTRANSFER => TRUE,
        CURLOPT_HTTPHEADER => array(
            'Authorization: apikey '.$authToken,
            'Content-Type: application/json'
        ),
        CURLOPT_POSTFIELDS => json_encode($postData)
    ));

    // Send the request
    $response = curl_exec($ch);

    return $response;
}
4

1 回答 1

0

它有效,但我不知道我还能做什么......,代码:

foreach($members as $member) {

   $list[] = $member->email;

}

$Mailer->tag_mailchimp('12345678', $list, 123456, 'members_to_remove');

在课堂上,我有下一个功能:

public function tag_mailchimp($list_id, $email, $tag, $method) {

        $authToken = 'HERE MY KEY';
        // The data to send to the API


        $postData = array(
            $method => $email
        );

        // Setup cURL
        $ch = curl_init('https://us2.api.mailchimp.com/3.0/lists/'.$list_id.'/segments/'.$tag);

        curl_setopt_array($ch, array(
            CURLOPT_POST => TRUE,
            CURLOPT_RETURNTRANSFER => TRUE,
            CURLOPT_HTTPHEADER => array(
                'Authorization: apikey '.$authToken,
                'Content-Type: application/json'
            ),
            CURLOPT_POSTFIELDS => json_encode($postData)
        ));

        // Send the request
        $response = curl_exec($ch);

        return $response;
    }
于 2020-06-15T11:10:20.867 回答