示例#1
1
 function AddSubscriberToList($emailAddress, $listIDs, $subscriberKey = null)
 {
     $newSub = new ET_Subscriber();
     $newSub->authStub = $this;
     $lists = array();
     foreach ($listIDs as $key => $value) {
         $lists[] = array("ID" => $value);
     }
     //if (is_string($emailAddress)) {
     $newSub->props = array("EmailAddress" => $emailAddress, "Lists" => $lists);
     if ($subscriberKey != null) {
         $newSub->props['SubscriberKey'] = $subscriberKey;
     }
     /*} else if (is_array($emailAddress)) {
     			$newSub->props = array();
     			for ($i = 0; $i < count($emailAddress); $i++) {
     				$copyLists = array();
     				foreach ($lists as $k => $v) {
     					$NewProps = array();
     					foreach($v as $prop => $value) {
     						$NewProps[$prop] = $value;
     					}
     					$copyLists[$k] = $NewProps;
     				}
     				
     				$p = array("EmailAddress" => $emailAddress[$i], "Lists" => $copyLists);
     				if (is_array($subscriberKey) && $subscriberKey[$i] != null) {
     					$p['SubscriberKey']  = $subscriberKey[$i];
     				}
     				$newSub->props[] = $p;
     			}
     		}*/
     // Try to add the subscriber
     $postResponse = $newSub->post();
     if ($postResponse->status == false) {
         // If the subscriber already exists in the account then we need to do an update.
         // Update Subscriber On List
         if ($postResponse->results[0]->ErrorCode == "12014") {
             $patchResponse = $newSub->patch();
             return $patchResponse;
         }
     }
     return $postResponse;
 }
 /**
  * @param $list Publication List ID
  * @param $email Email Address / SubscriberKey
  * @param $status Status /Unsubscribed-Active
  * @return bool|\ET_Patch
  */
 public function UpdateListSubscriber($list, $email, $status)
 {
     $s = new \ET_Subscriber();
     $s->authStub = $this->fuel;
     $s->props = array("SubscriberKey" => $email, "Lists" => array("ID" => $list), "Status" => $status);
     $getRes = $s->patch();
     if ($getRes->status == true) {
         return $getRes;
     } else {
         Log::error('Error getting UpdateListSubscribers ET (UpdateListSubscribers)', [$getRes]);
         return false;
     }
 }
 print 'Code: ' . $postResult->code . "\n";
 print 'Message: ' . $postResult->message . "\n";
 print 'Results Length: ' . count($postResult->results) . "\n";
 print 'Results: ' . "\n";
 print_r($postResult->results);
 print "\n---------------\n";
 if (!$postResult->status) {
     // If the subscriber already exists in the account then we need to do an update.
     // Update Subscriber On List
     if ($postResult->results[0]->ErrorCode == "12014") {
         // Update Subscriber to add to List
         print "Update Subscriber to add to List \n";
         $subPatch = new ET_Subscriber();
         $subPatch->authStub = $myclient;
         $subPatch->props = array("EmailAddress" => $SubscriberTestEmail, "Lists" => array("ID" => $newListID));
         $patchResult = $subPatch->patch();
         print_r('Patch Status: ' . ($patchResult->status ? 'true' : 'false') . "\n");
         print 'Code: ' . $patchResult->code . "\n";
         print 'Message: ' . $patchResult->message . "\n";
         print 'Results Length: ' . count($patchResult->results) . "\n";
         print 'Results: ' . "\n";
         print_r($patchResult->results);
         print "\n---------------\n";
     }
 }
 // Retrieve all Subscribers on the List
 print "Retrieve all Subscribers on the List \n";
 $getList = new ET_List_Subscriber();
 $getList->authStub = $myclient;
 $getList->filter = array('Property' => 'ListID', 'SimpleOperator' => 'equals', 'Value' => $newListID);
 $getList->props = array("ObjectID", "SubscriberKey", "CreatedDate", "Client.ID", "Client.PartnerClientKey", "ListID", "Status");