MailChimp API 3.0 批量更新 - 始终待定,total_operations:0
MailChimp API 3.0 Batch update - Always pending, total_operations:0
正在尝试更新一批电子邮件。我想我已经尝试了各种方法来做到这一点,但我对 DrewM's MailChimp wrapper 的使用仅 returns 以下 $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 的代表交谈后,他帮助发现了两个主要问题。
他说在处理已经存在的电子邮件时使用 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 长筒袜作为一项很好的运动:-)
维尼。维迪。维西
正在尝试更新一批电子邮件。我想我已经尝试了各种方法来做到这一点,但我对 DrewM's MailChimp wrapper 的使用仅 returns 以下 $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 的代表交谈后,他帮助发现了两个主要问题。
他说在处理已经存在的电子邮件时使用 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 长筒袜作为一项很好的运动:-)
维尼。维迪。维西