【发布时间】:2017-11-23 12:16:44
【问题描述】:
我已使用此功能通过 Mailchimp API v3.0 获取特定活动的详细信息。
function mc_insert_campaign($email, $apikey, $server) {
$apiKey = 'xxxxxxxxxxxxmyAPI';
$camp_id = '1753ef2cce';
$auth = base64_encode( 'user:'. $apikey );
$data = array(
'apikey' => $apikey,
'id' => $camp_id
);
$json_data = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://'.$server.'.api.mailchimp.com/3.0/campaigns/'. $camp_id);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
'Authorization: Basic '. $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_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
$result = curl_exec($ch);
// if ($debug) {
// var_dump($result);
// }
$json = json_decode($result);
$camp_type = $json->{'type'};
echo $camp_type;
}
到目前为止,它对我来说还可以,因为我正在采用广告系列类型。 但我也需要提取主题行。
我在 MC API 文档中读到的 json 答案看起来像:
{
"id": "42694e9e57",
"type": "regular",
"create_time": "2015-09-15T14:40:36+00:00",
"archive_url": ".....",
"status": "save",
"emails_sent": 0,
"send_time": "",
"content_type": "template",
"recipients": {
"list_id": "57afe96172",
"segment_text": ""
},
"settings": {
"subject_line": "I have a rice crispy treat watermelon farm.",
"title": "Freddie's Jokes Vol. 1",
"from_name": "Freddie",
"reply_to": "freddie@freddiesjokes.com",
"use_conversation": false,
"to_name": "",
"folder_id": 0,
"authenticate": true,
"auto_footer": false,
"inline_css": false,
"auto_tweet": false,
"fb_comments": false,
"timewarp": false,
"template_id": 100,
"drag_and_drop": true
}, .........
我尝试过类似的东西
$camp_type = $json->{'settings'}{'type'};
但它没有奏效。我究竟做错了什么? 提前谢谢你..
【问题讨论】:
-
您从哪里获得广告系列 ID?你的似乎是 10 个字母数字字符,我的似乎是 7 个数字。