0

我正在开发一个活动监视器 api,它创建一个带有自定义字段的自定义列表。

当我尝试添加订阅者时,它曾经可以工作,现在当我查看列表时,它没有添加它们。虽然它仍然返回成功代码 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;
}
4

1 回答 1

1

此代码对我有用。您需要在项目文件夹中添加活动监视器类文件并使用有效的列表 ID 和 api 密钥。您可以从管理帐户链接和列表 ID 中找到您的 api 密钥(更改名称/类型)下面的列表标题。请等待一段时间才能在您的列表中看到。

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>';
}
于 2015-10-26T14:00:59.087 回答