當前位置: 首頁>>代碼示例>>PHP>>正文


PHP MCAPI::listBatchUnsubscribe方法代碼示例

本文整理匯總了PHP中MCAPI::listBatchUnsubscribe方法的典型用法代碼示例。如果您正苦於以下問題:PHP MCAPI::listBatchUnsubscribe方法的具體用法?PHP MCAPI::listBatchUnsubscribe怎麽用?PHP MCAPI::listBatchUnsubscribe使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在MCAPI的用法示例。


在下文中一共展示了MCAPI::listBatchUnsubscribe方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: processMailChimpUsers

 /**
  * Runs through all the MailChimp users for a given list
  *
  * @param string $listId
  */
 protected function processMailChimpUsers($listId)
 {
     $unsubscribe = array();
     $start = 0;
     do {
         $batch = $this->_mailChimp->listMembers($listId, 'subscribed', null, $start, $this->_batchSize);
         $start++;
         foreach ($batch['data'] as $row) {
             if (!$this->userExists($row['email'], $listId)) {
                 $unsubscribe[] = $row['email'];
             }
         }
     } while (count($batch['data']) == $this->_batchSize);
     $unsubscribe = array_chunk($unsubscribe, $this->_batchSize);
     foreach ($unsubscribe as $i => $batch) {
         $batchResult = $this->_mailChimp->listBatchUnsubscribe($listId, $batch, true, $this->_mailChimpOptions['sendGoodby'], $this->_mailChimpOptions['sendNotify']);
         if (!$batchResult) {
             throw new Galahad_MailChimp_Synchronizer_Exception('Error with batch unsubscribe: ' . $this->_mailChimp->errorMessage);
         } else {
             $this->_batchLog[] = "Unsubscribe Batch {$i}: {$batchResult['success_count']} Succeeded";
             $this->_batchLog[] = "Unsubscribe Batch {$i}: {$batchResult['error_count']} Failed";
             if ($batchResult['error_count']) {
                 $this->_batchErrors["Unsubscribe Batch {$i}"] = $batchResult['errors'];
             }
         }
         unset($unsubscribe[$i]);
     }
     unset($batch);
     unset($unsubscribe);
 }
開發者ID:moogacs,項目名稱:Galahad-MailChimp-Synchronizer,代碼行數:35,代碼來源:Synchronizer.php

示例2: run

 public function run($args)
 {
     $subscribers = User::model()->findAllByAttributes(array('newsletter' => true, 'previous_newsletter_state' => false));
     $batch = array();
     foreach ($subscribers as $s) {
         $batch[] = array('EMAIL' => $s->email, 'FNAME' => $s->first_name, 'LNAME' => $s->last_name);
         $s->previous_newsletter_state = true;
         $s->save();
     }
     $api = new MCAPI(Yii::app()->params['mc_apikey']);
     $result = $api->listBatchSubscribe(Yii::app()->params['mc_listID'], $batch, false);
     if (isset($result['errors'])) {
         foreach ($result['errors'] as $e) {
             if ($e['code'] == 212) {
                 //User unsubscribed, need to resubscribe individually
                 $user = User::model()->findByAttributes(array('email' => $e['email']));
                 if ($user !== null) {
                     $info = array('FNAME' => $user->first_name, 'LNAME' => $user->last_name);
                     $api->listSubscribe(Yii::app()->params['mc_listID'], $user->email, $info);
                     if ($api->errorCode) {
                         echo "Subscribe {$user->email} failed!\n";
                         echo "code:" . $api->errorCode . "\n";
                         echo "msg :" . $api->errorMessage . "\n";
                     } else {
                         echo "Re-Subscribe {$user->email} Successfully\n";
                     }
                 }
             } else {
                 if ($e['code'] != 214) {
                     print_r($e);
                 }
             }
         }
     }
     $unsubscribers = User::model()->findAllByAttributes(array('newsletter' => false, 'previous_newsletter_state' => true));
     $batch = array();
     foreach ($unsubscribers as $u) {
         $batch[] = $u->email;
         $u->previous_newsletter_state = $u->newsletter = 0;
         $u->save();
     }
     $result = $api->listBatchUnsubscribe(Yii::app()->params['mc_listID'], $batch);
     if (isset($result['errors'])) {
         foreach ($result['errors'] as $e) {
             if ($e['code'] != 215) {
                 print_r($e);
             }
         }
     }
 }
開發者ID:jessesiu,項目名稱:GigaDBV3,代碼行數:50,代碼來源:MCSyncCommand.php

示例3: MCAPI

/**
This Example shows how to run a Batch Unsubscribe on a List using the MCAPI.php 
class and do some basic error checking or handle the return values.
**/
require_once 'inc/MCAPI.class.php';
require_once 'inc/config.inc.php';
//contains apikey
$api = new MCAPI($apikey);
$emails = array($my_email, $boss_man_email);
$delete = false;
//don't completely remove the emails
$bye = true;
// yes, send a goodbye email
$notify = false;
// no, don't tell me I did this
$vals = $api->listBatchUnsubscribe($listId, $emails, $delete, $bye, $notify);
if ($api->errorCode) {
    // an api error occurred
    echo "code:" . $api->errorCode . "\n";
    echo "msg :" . $api->errorMessage . "\n";
} else {
    echo "success:" . $vals['success_count'] . "\n";
    echo "errors:" . $vals['error_count'] . "\n";
    foreach ($vals['errors'] as $val) {
        echo "\t*" . $val['email'] . " failed\n";
        echo "\tcode:" . $val['code'] . "\n";
        echo "\tmsg :" . $val['message'] . "\n\n";
    }
}
?>
 
開發者ID:uiDeveloper116,項目名稱:webstore,代碼行數:30,代碼來源:mcapi_listBatchUnsubscribe.php

示例4: getMergeVars

    if (!isset($report_members[strtolower($member['email'])])) {
        $to_remove[] = $member['email'];
    }
}
if ($DEBUG > 1) {
    bam("LIST MEMBERS:");
    bam($list_members);
    bam("==================");
}
if ($DEBUG && !empty($to_remove)) {
    bam("TO REMOVE:");
    bam($to_remove);
    bam("==================");
}
if (!empty($to_remove) && !$DRYRUN) {
    $api->listBatchUnsubscribe($list_id, $to_remove, true, false, false);
    // delete them completely; don't send goodbye; don't send notification to admin.
}
if (!empty($api->errorMessage)) {
    trigger_error("Mailchimp API Error calling listBatchUnsubscribe(): " . $api->errorMessage, E_USER_ERROR);
}
exit(0);
//// HELPER FUNCTION ////
function getMergeVars($person_data, $email)
{
    static $dummy_person = null;
    if (is_null($dummy_person)) {
        $GLOBALS['system']->includeDBClass('person');
        $dummy_person = new Person();
    }
    $dummy_person->populate(0, $person_data);
開發者ID:howardgrigg,項目名稱:jethro-pmm,代碼行數:31,代碼來源:mailchimp_sync.php


注:本文中的MCAPI::listBatchUnsubscribe方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。