【问题标题】:Add subscrber to mailchimp API v3将订阅者添加到 mailchimp API v3
【发布时间】:2018-05-15 19:54:35
【问题描述】:

我写了这个函数:

public function mailchimp() {

$email = 'testing123@test.com';
$first_name = 'Test';
$last_name = 'Test';

$api_key = 'dfrgergredgdfgdfgdfgdfg-us9'; // YOUR API KEY

// server name followed by a dot. 
// We use us13 because us13 is present in API KEY
$server = 'us9.'; 

$list_id = '718943'; // YOUR LIST ID

$auth = base64_encode( 'user:'.$api_key );

$data = array(
    'apikey'        => $api_key,
    'email_address' => $email,
    'status'        => 'subscribed',
    'merge_fields'  => array(
        'FNAME' => $first_name,
        'LNAME'    => $last_name
        )    
    );
$json_data = json_encode($data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://'.$server.'api.mailchimp.com/3.0/lists/'.$list_id.'/members/');
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_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);

$result = curl_exec($ch);

$result_obj = json_decode($result);

// printing the result obtained    
echo $result_obj->status;
echo '<br>';
echo '<pre>'; print_r($result_obj); echo '</pre>';

    }

但我得到了这个结果(404 错误),我不知道该怎么做以及我错在哪里:

404
stdClass Object
(
    [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] => 637c9154-9999-48d2-952f-e994b737a9b7
)

这里有什么问题?为什么我会收到 404 错误?我在任何地方都看不到我的代码中的错误。我该如何解决这个问题?

我使用 Laravel 5.1 对不起我的英语!

【问题讨论】:

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


    【解决方案1】:

    这似乎与您的列表 ID 有关。我不确定您是否在问题中替换了您的真实列表 ID,但其格式应该类似于 z1593c999e 而不仅仅是数字。 API 所需的列表 ID 与您在 MailChimp 中查看列表时在 URL 中看到的不同。

    要找到这个,您可以在 MailChimp 的知识库中follow these steps

    1. 导航到列表页面。
    2. 点击您要使用的列表旁边的下拉菜单,然后选择设置。
    3. 滚动查找唯一的列表 ID 字段。由字母和数字组成的字符串就是列表 ID。

    您也可以使用 GET 方法向https://usX.api.mailchimp.com/3.0/lists 发送 API 请求,并在响应中找到列表 ID。

    【讨论】:

      猜你喜欢
      • 2017-08-07
      • 2015-08-09
      • 2016-01-02
      • 2015-11-26
      • 2017-11-26
      • 2016-06-12
      • 2015-05-18
      相关资源
      最近更新 更多