【问题标题】:Setting schedule_time in mailchimp 3.0 causes error在 mailchimp 3.0 中设置 schedule_time 会导致错误
【发布时间】:2017-01-31 19:20:34
【问题描述】:

我是这样做的:

$debug = true;
$auth = base64_encode( 'user:'. APIKEY );

$data = array(
    'schedule_time' => date('Y-m-d H:i:s',strtotime("+1 hour")),
    'timewarp' => false
    );
$json_data = json_encode($data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://'.SERVER.'.api.mailchimp.com/3.0/campaigns/'.$campaign_id.'/actions/schedule');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
    'Authorization: Basic '. $auth));
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);

$result = curl_exec($ch);

if ($debug) {
    var_dump($result);
}

这会报错:

schedule_time 只能以 15 分钟为间隔,例如13:15 不是 13:10

【问题讨论】:

    标签: php curl mailchimp-api-v3.0


    【解决方案1】:

    这是旧的,但也可以为其他偶然发现此问题的人提供答案:

    因此,正如错误消息所述,您只能将广告系列安排为 15 分钟的倍数,例如 X:00、X:15、X:30 和 X:45。因此,您使用

    date('Y-m-d H:i:s',strtotime("+1 小时"))

    意味着你的日程安排总是会失败,除非你得到一些非常好的时机。

    我发现有用的是为用户提供一个步长为 15 的 Timepicker 下拉菜单:

    $('.timepicker').timepicker({ 'scrollDefault': 'now', 'step': 15, 'timeFormat': 'H:i' });

    与典型的日期选择器一样,当触发调度时,我会将两者组合成 Mailchimp 想要的 ATOM 格式:

        var date = $("#schedule_date").val(); //Date from the Datepicker     
        var time = $("#schedule_time").val(); //Time from the 15min step Timepicker   
        var offset = new Date().getTimezoneOffset()/60; // I believe Mailchimp likes to have it in UTC    
        var datetime=new Date(date+'T'+time+':00'+((offset<0)?"+":"-")+((offset>-10 && offset<10)?"0":"")+offset+':00');  // Constructing ATOM time (example: 2005-08-15T15:52:01+00:00)    
        var datestring = datetime.toISOString();   
        datestring = datestring.substring(0, datestring.length - 5)+'+00:00';  
    

    【讨论】:

    • 你能把最好的日期例子贴在这里,我可以试试
    猜你喜欢
    • 1970-01-01
    • 2016-07-05
    • 2015-12-16
    • 2013-02-14
    • 1970-01-01
    • 2011-06-05
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多