【发布时间】:2015-03-04 08:35:48
【问题描述】:
我正在运行 MailChimp subscribe API 调用。发送的 JSON 对象如下所示:
{
"apikey":"someAPIkey-us10",
"id":"someID",
"email":{
"email":"example@su.vi"
},
"merge_vars":{
"products":[
{
"name":"prod",
"url":"https:\/\/www.example.co.uk\/properties\/link\/sub\/res",
"price":"\u00a3378.00",
"location":"loc",
"area":"are"
}
]
},
"double_optin":false
}
执行curl对象的php代码如下:
$curl = curl_init(SEED_URL);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $jsonStr);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array(
"Accept: application/json",
"Content-Type: application/json",
"Content-Length: " . strlen($jsonStr)
)
);
$response = curl_exec($curl);
var_dump($response);
$responseCode = curl_getinfo ($curl , CURLINFO_HTTP_CODE);
if ($responseCode !== 201) {
throw new Exception("post failed with response code " . $responseCode . " " . $jsonStr, 1);
}
$response 转储有效,如下所示:
"{"email":"example@su.vi","euid":"someEUID","leid":"someLEID"}"
然而一个
发布失败,响应代码为 200。
被抛出,并且订阅者列表未填充到 mailChimp 服务器中。
【问题讨论】:
-
现在可以在列表中看到您的新订阅者了吗?
-
@Pierre-JeanBergeron,我愿意。但问题不在于等待。这是因为我先将
email传递给subscribe方法,然后将apikey传递给subscribe方法。我又看了一遍文档,并按照参数顺序。谢谢 beaucoup quand meme! :)
标签: php httpresponse mailchimp