Php MailChimp API:批量检查订阅状态

Php MailChimp API:批量检查订阅状态,php,api,mailchimp,Php,Api,Mailchimp,检查一批电子邮件地址以及它们是否已订阅特定列表的最佳方法是什么?我当前的方法是对每个电子邮件地址进行API调用,但当计数大于50时,这会变得非常缓慢 我使用V2.0,使用PHP方法,因为我是在CakePHP上开发的 //Determine MailChimp Subscription $args = array( 'id' => $this->apiKeys['mailchimp_list_ID'], 'emails' => array(1 => ar

检查一批电子邮件地址以及它们是否已订阅特定列表的最佳方法是什么?我当前的方法是对每个电子邮件地址进行API调用,但当计数大于50时,这会变得非常缓慢

我使用V2.0,使用PHP方法,因为我是在CakePHP上开发的

 //Determine MailChimp Subscription
 $args = array(
    'id' => $this->apiKeys['mailchimp_list_ID'],
    'emails' => array(1 => array('email' => $customer['User']['username']))
 );
 $mailChimpQuery = $this->mailChimp('member-info', $args);
 $mailChimpStatus = ($mailChimpQuery['success_count'] == 1 ? 1 : 0);
 $customer['Customer']['subscribed'] = $mailChimpStatus;
另一个控制器中的
mailChimp
调用是:

public function mailChimp($action, $args=array()) {

        $args['apikey'] = $this->apiKeys['mailchimp_api'];
        $url = 'https://us8.api.mailchimp.com/2.0/lists/' . $action .'.json';

        if (function_exists('curl_init') && function_exists('curl_setopt')){
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
            curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_TIMEOUT, 10);
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($args));
            $result = curl_exec($ch);
            curl_close($ch);
        } else {
            $json_data = json_encode($args);
            $result    = file_get_contents($url, null, stream_context_create(array(
                'http' => array(
                    'protocol_version' => 1.1,
                    'user_agent'       => 'PHP-MCAPI/2.0',
                    'method'           => 'POST',
                    'header'           => "Content-type: application/json\r\n".
                    "Connection: close\r\n" .
                    "Content-length: " . strlen($json_data) . "\r\n",
                    'content'          => $json_data,
                    ),
                )));
        }

        return  $result ? json_decode($result, true) : false;
    }

仅供参考,我提出了自己的解决方案:

  • 创建数据库中所有电子邮件地址的数组
  • 创建一个for循环,从该数组中获取50个电子邮件地址的段,并使用成员信息运行批处理检查
  • 操纵API调用中的返回数组,以仅提取电子邮件地址以及该地址是否已订阅列表
  • 在for循环中,将每50个电子邮件地址的返回值添加到一个新数组中,然后添加到该数组的末尾;您的数据库中将有一个包含所有电子邮件地址的数组,该数组具有相应的真/假值,具体取决于它们是否已订阅列表
  • 祝你好运