本文整理汇总了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);
}
示例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);
}
}
}
}
示例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";
}
}
?>
示例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);