2015-10-15 30 views
0

我正在創建一個活動監視器api,它使用自定義字段創建一個自定義列表。Campaign Monitor php sdk - 添加訂閱錯誤 - 不再顯示在列表中

當我嘗試添加過去用於工作的訂閱者時,現在當我查看列表中沒有添加它們時。雖然它仍返回成功碼201

function addSubscriber($list_id, $emailAddress, $name, $title, $showName, $showDate, $showTime){ 
    //create subscriber 
    $subscriber = array(
     'EmailAddress' => $emailAddress, 
     'Name' => $name, 
     'CustomFields' => array(
      array(
       'Key' => "Title", 
       'Value' => $title 
      ), 
      array(
       'Key' => "ShowName", 
       'Value' => $showName 
      ), 
      array(
       'Key' => "ShowDate", 
       'Value' => $showDate 
      ), 
      array(
       'Key' => "ShowTime", 
       'Value' => $showTime 
      ) 
     ), 
     'Resubscribe' => true, 
     'RestartSubscriptionBasedAutoResponders' => true 
    ); 

    //print_r($subscriber); 

    $subwrap = new CS_REST_Subscribers($list_id, $this->auth); 
    $result = $subwrap->add($subscriber); 
    //var_dump($result->response); 

    echo "Result of POST /api/v3.1/subscribers/{list id}.{format}\n<br />"; 
    if($result->was_successful()) { 
     echo "Subscribed with code ".$result->http_status_code; 
    } else { 
     echo 'Failed with code '.$result->http_status_code."\n<br /><pre>"; 
     var_dump($result->response); 
     echo '</pre>'; 
    } 
    return $result->response; 
} 

回答

1

此代碼工作me.You需要添加的Campaign Monitor類文件在您的項目文件夾,並使用有效的列表ID和API key.You可以找到你的API密鑰從管理帳戶鏈接和列表ID從點擊(更改名稱/類型)下面的列表標題。請稍等一會兒,看看你的名單。

require_once 'csrest_subscribers.php'; 


$name=$_POST['name']; 
$email=$_POST['email']; 


$wrap = new CS_REST_Subscribers('Your list ID', 'Your API Key'); 
$result = $wrap->add(array(
    'EmailAddress' => $email, 
    'Name' => $name, 
    'CustomFields' => array(), // no custom fields, can remove this line completely 
    'Resubscribe' => true 
)); 


echo "Result of POST /api/v3/subscribers/{list id}.{format}\n<br />"; 
if($result->was_successful()) { 
    echo "Subscribed with code ".$result->http_status_code; 
} else { 
    echo 'Failed with code '.$result->http_status_code."\n<br /><pre>"; 
    var_dump($result->response); 
    echo '</pre>'; 
} 
+0

是的你是對的。我以某種方式重構了代碼 - 它無法訪問實例 –

相關問題