2017-06-20 97 views
0

我已使用此功能使用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": "[email protected]", 
    "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'}; 

,但它並沒有奏效。我究竟做錯了什麼? 預先感謝您..

回答

0

最後我找到了解決方案...我想這是非常基本的,但我發佈它無論如何,以防萬一有興趣!

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

反正!

相關問題