【问题标题】:How do I add email address to MailChimp list using API如何使用 API 将电子邮件地址添加到 MailChimp 列表
【发布时间】:2016-07-18 08:29:24
【问题描述】:

我正在尝试使用 MailChimp API 3.0 使用下面的代码将电子邮件地址添加到现有列表,但它不断抛出此 错误 消息。请问谁能告诉我我的代码有什么问题?

401:您的 API 密钥可能无效,或者您试图访问 错误的数据中心。

代码:

$apikey = "xxxxxxxxxxxxxxxxxxxxxxxx-us9";
$list_id = "xxxxxxxxxx";
$MD5_hashed_email_address = md5(strtolower($to_email));
$auth = base64_encode("user:$apikey");

$data = array(
    "apikey" => $apikey,
    "email_address" => $to_email,
    "status" => "subscribed",
    "merge_fields" => array(
        "FNAME" => $firstname,
        "LNAME" => $surname
    )
);
$json_data = json_encode($data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://us9.api.mailchimp.com/3.0/lists/$list_id/members/");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json",
    'Authorization: apikey ' . $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);

【问题讨论】:

    标签: php mailchimp


    【解决方案1】:

    试试这个:

    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", 'Authorization: Basic ' . $auth));

    【讨论】:

      猜你喜欢
      • 2019-05-29
      • 2014-04-17
      • 2018-01-06
      • 2011-05-07
      • 2017-04-16
      • 2014-04-03
      • 2014-09-21
      • 2015-12-29
      • 2014-04-03
      相关资源
      最近更新 更多