0
MailChimp API 3.0を使用して既存のリストにこのコードを使用して電子メールアドレスを追加しようとしていますが、このメッセージはエラーというメッセージです。私のコードに何が間違っているか教えてください。APIを使用してMailChimpリストに電子メールアドレスを追加するには
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);