【问题标题】:404 error when using MailChimp API with CodeIgniter使用带有 CodeIgniter 的 MailChimp API 时出现 404 错误
【发布时间】:2017-08-16 22:52:55
【问题描述】:

我正在尝试集成 MailChimp API。我切换了两个不同的库并得到相同的错误。

[type] => http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/
[title] => Resource Not Found
[status] => 404
[detail] => The requested resource could not be found.
[instance] => 

很遗憾,这个错误没有为我提供任何有用的信息。我使用的库是this one

这是我在控制器中使用的代码:

function __construct(){
    parent::__construct(); 

    $this->load->library('mailchimp');
    $this->common = array(
        'list_id'   =>  '12345678',
    );
}

public function signup() {      

    $form = $this->input->post();

    if ( !empty($form['website']) ) {

        // If Honey Pot is filled out
        redirect('https://www.google.com');

    } else {

        $result = $this->mailchimp->call('POST', 
            'lists/'.$this->common['list_id'].'/members', 
            array(
                'email_address' =>  $form['email'], 
                'merge_fields'  =>  array( 
                        "FNAME" =>  $form['first_name'], 
                        "LNAME" =>  $form['last_name'] 
                    ), 
                'status'        =>  'subscribed',
            )
        );

        debug($result);
        return true;

        // Check Result
        if ( $result['status'] !== 'subscribed' && $result['status'] !== 'pending' ) {

            return false;

        } else {

            return true;

        }

    }       
}

debug 函数是我的一个助手,它可以将 print_r 包裹在 <pre> 中,让我的生活更轻松。

我希望这只是盯着屏幕太久而错过了明显的东西或者 MailChimp API 有问题的情况。

【问题讨论】:

    标签: php codeigniter mailchimp


    【解决方案1】:

    我解决了这个问题,我有错误的 API 密钥和数据中心,他们的消息应该更清晰。为了避免再次出现这个错误,我在我的配置文件中编写了以下内容。

    $config['api_key'] = '1276381263872163872163872-us11';
    $data_center = explode("-", $config['api_key']);
    $config['api_endpoint'] = 'https://'.$data_center[1].'.api.mailchimp.com/3.0/';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-13
      • 2014-08-03
      • 1970-01-01
      • 2017-03-06
      • 2016-07-12
      • 2014-05-26
      • 2017-09-03
      • 2023-03-11
      相关资源
      最近更新 更多