mailchimp 3.0 身份验证失败

mailchimp 3.0 authentication fails

以下身份验证失败,使用 CURL 将其发布到 mailchimp,其中 API_KEY 定义为包含我的密钥的字符串。类似的代码曾经适用于 mailchimp v2:

$params = array ('apikey' => API_KEY,
                 'email_address' => $email,
                 'status' => 'pending',
                 'merge_fields' => array ('fname' => $first_name,
                                          'lname' => $last_name
                                         )
                );

错误是:

{"type":"http://kb.mailchimp.com/api/error-docs/401-api-key-missing",
 "title":"API Key Missing",
 "status":401,"detail":
 "Your request did not include an API key.",
 "instance":"(long number)"
}

这不是 v3.0 中身份验证的工作方式。来自 the documentation:

The easiest way to authenticate is using HTTP Basic Auth. Enter any string as the username and supply your API Key as the password. Your HTTP client library should have built-in support for basic authorization.

如果您使用 PHP,每个 HTTP 库都知道如何执行此操作。我推荐 Guzzle 或 PHP Requests,但甚至 basic cURL in PHP can do basic auth easily.

interests 语法看起来不错,只是值应该是布尔值而不是字符串。