使用mailchimp API v3.0获取活动主题行

时间:2017-06-20 19:44:04

标签: json mailchimp-api-v3.0

我已使用此功能使用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'};

但它没有奏效。我究竟做错了什么? 提前谢谢..

1 个答案:

答案 0 :(得分:1)

最后我找到了解决方案......我想这是非常基本的,但无论如何我都会张贴它以防万一有兴趣!

解决方案是:$ camp_subject_line = $ json-> settings-> {' subject_line'}。

无论如何,

Thanx!