邮件黑猩猩 API 3.0 批处理更新 - 始终挂起,total_operations:0


MailChimp API 3.0 Batch update - Always pending, total_operations:0

正在尝试更新一批电子邮件。我想我已经尝试了所有方法来做到这一点,但我使用 DrewM 的 MailChimp 包装器只返回以下$result内容:

Array ( [id] => 1234abcd [status] => pending [total_operations] => 0 [finished_operations] => 0

等等。没有错误,但没有操作!

本质上,我的代码看起来像这样,$emails将所有电子邮件存储在一个数组中。

include("MailChimp.php");
include("Batch.php");
$list_id = "1234abcd";
use 'DrewM'MailChimp'MailChimp;
use 'DrewM'MailChimp'Batch;
$apiKey = 'aslkjf84983hg84938h89gd-us13';
if(!isset($emails)){ // If not sending bulk requests
    $MailChimp = new MailChimp($apiKey);
    $subscriber_hash = $MailChimp->subscriberHash($email);
    $result = $MailChimp->patch("lists/$list_id/members/$subscriber_hash",
        array(
            'status' => 'subscribed',
        )
    );
/* SENDING BATCH OF EMAILS */
} else if($emails){
    $MailChimp = new MailChimp($apiKey);
    $Batch     = $MailChimp->new_batch();
    $i = 1;
    foreach($emails as &$value){
        $Batch->post("op".$i, "lists/$list_id/members", [
            'email_address' => $value,
            'status'        => 'subscribed',
        ]);
        $i++;
    }
    $result = $Batch->execute(); // Send the request (not working I guess)
    $MailChimp->new_batch($batch_id); // Now get results
    $result = $Batch->check_status();
    print_r($result);
}

如果有人能看到我没有看到的东西,我将不胜感激!

问题解决了。在与MailChimp的代表交谈后,他帮助发现了两个主要问题。

他说,在处理已经存在的电子邮件时,他没有使用POST方法,而是使用PUT。POST 最适合用于添加电子邮件,而 PUT 可以添加和更新电子邮件。

所以,改变

$Batch->post

$Batch->put

其次,在成功发送请求并在$result中出现错误后,他发现它们是 405 错误,并告诉我将md5哈希添加到我的电子邮件中。

所以,改变

$Batch->post("op".$i, "lists/$list_id/members", [ ...

$subscriber_hash = $MailChimp->subscriberHash($value);
$Batch->put("op$i", "lists/$list_id/members/$subscriber_hash", [ ...

他们给我寄了一个MailChimp袜帽,因为这是一项很好的运动:-)

维尼。维迪.