Mailchimp API 2.0出错时的记录数>大约500

时间:2015-06-02 13:34:38

标签: php api batch-processing mailchimp

使用DrewM的MailChimp API v2包装器我试图用大约700行的列表批量订阅来更新我的列表。

当处理多达500行时,我没有任何问题,但在此之后,列表似乎更新了OK,但没有返回任何内容。

我以为我找到了这篇类似帖子的答案[Mailchimp Batch Subscribe 2.0 Returns False on 500+ records (PHP)

但问题仍然存在

我也按照建议尝试了超时(脚本似乎运行了大约10秒)

<?php
//loop through the recordset and create the batch array
 while(!$rscontacts->atEnd()) {

$merge_vars = array(
                'FNAME'=>    $rscontacts->getColumnVal("FirstName"),
                'LNAME'=>    $rscontacts->getColumnVal("LastName"),
                'CONTACTID'=>  $rscontacts->getColumnVal("ContactID"),
                'CONTTYPE'=>  $rscontacts->getColumnVal("ContactTypeID"),
                'ACTIVE'=>  $rscontacts->getColumnVal("Active"),
                'INMAILING'=>  $rscontacts->getColumnVal("InMailing")                  
               );                  
$batch[] = array(
    'email' => array('email' => $rscontacts->getColumnVal("EmailAddress1")),
    "email_type" => "html", // optional, for the email type option (html or              text)
    'merge_vars' => $merge_vars
    );

    $rscontacts->moveNext();
}
$rscontacts->moveFirst(); //return RS to first record
//print_r($batch);
?>
...
<?php 
set_time_limit(0);
$api = 'xxx';
$mcListId = 'xxx';
$MailChimp = new \Drewm\MailChimp(xxx);

$retval = $MailChimp->call("lists/batch-subscribe", array(
  "id" => $mcListId, 
  "batch" => $batch,
  "double_optin" => false, 
  "update_existing" => true, 
  "replace_interests" => true // optional, flag to determine whether we        replace the interest groups with the updated groups provided, or we add the provided groups to the member's interest groups
));
  if ($retval === false) {
echo "Mailchimp API returned false";
  }
?>
<?php echo $retval ['add_count'].' Records added'; ?><br>
<?php echo $retval ['update_count'].' Records updated'; ?><br>
<?php echo $retval ['error_count'].' Errors Found'; ?><br>

  [1]: https://stackoverflow.com/questions/29082925/mailchimp-batch-subscribe-2-0-returns-false-on-500-records-php

1 个答案:

答案 0 :(得分:0)

修正了它!

在MailChimp.php的脚本中,有2个$ timeout参数。

脚本在10秒时超时,我需要将调用函数设置为更高的值 - 现在脚本(运行大约需要14秒)执行正常