我想通过MailChimp API创建广告系列。我正在使用下面的代码。
$data = ["recipients" => ["list_id" => "a332819b0b"], "type" => "regular", "settings" => ["subject_line" => "Subject", "title" => "Title", "reply_to" => "test@gmail.com", "from_name" => "Test"]];
$data = json_encode($data);
$curl = curl_init();
curl_setopt_array($curl, [
//Sample url
CURLOPT_URL => "https://us17.api.mailchimp.com/3.0/campaigns",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $data,
CURLOPT_HTTPHEADER => ["apikey:MY_API_KEY"],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
$response = $err;
}
die($response);
我得到的输出如下。
有人能帮我解决这个问题吗?感谢。
答案 0 :(得分:0)
你几乎已经开始工作了。只需将CURLOPT_HTTPHEADER
行替换为CURLOPT_USERPWD
,如下所示:
CURLOPT_USERPWD => "apikey:abc123abc123abc123abc123abc123-us10"
当然,您希望在那里使用自己的API密钥,它应该可以正常工作。