【问题标题】:MailChimp API 3.0 Batch update - Always pending, total_operations:0MailChimp API 3.0 批量更新 - 始终挂起,total_operations:0
【发布时间】:2016-07-26 03:03:37
【问题描述】:

尝试更新一批电子邮件。我想我已经尝试了各种方法来做到这一点,但我对DrewM's MailChimp wrapper 的使用只返回以下$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);
}

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

【问题讨论】:

    标签: php mailchimp


    【解决方案1】:

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

    他说在处理现有电子邮件时使用PUT,而不是使用POST 方法。 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 袜子帽,因为它是一项很好的运动 :-)

    维尼。维迪。维西。

    【讨论】:

      猜你喜欢
      • 2016-09-04
      • 2019-01-20
      • 2018-10-05
      • 2015-11-24
      • 2020-09-27
      • 2019-05-16
      • 2016-07-10
      • 2015-12-18
      • 1970-01-01
      相关资源
      最近更新 更多