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

Get campaign subject line with 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'};

但是没有用。我究竟做错了什么? 提前谢谢你..

我终于找到了解决方案...我想这是非常基本的,但我还是将其发布以防万一有人感兴趣!

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

无论如何谢谢!