2011-06-17 13 views
5

का उपयोग कर रहा बना सकते हैं और तुरंत MailChimp.com में अभियानों भेजने की जरूरत बनाने के लिए। मैंने इस उद्देश्य के लिए C# wrapper Percepective MCAPI.dll का उपयोग किया।कैसे MailChimp में एक अभियान ASP.Net

MailChimp API से

, इसका स्पष्ट है कि हम सूचियों नहीं कर सकते हैं लेकिन अभियान बना सकते हैं। मैंने कोड की कोशिश की लेकिन campaignID is retured null; कम से कम कोई अपवाद नहीं फेंक दिया। मैंने campaigntype to Auto सेट किया था।

 
try 
{ 
    string apiKey = "api-us2"; // API KEY is valid 
    string emailAddress = "[email protected]"; 
    listsForEmailInput lstForEmailInput = new listsForEmailInput(apiKey, emailAddress); 
    listsForEmail cmd = new listsForEmail(lstForEmailInput); 
    listsForEmailOutput lstEmailOutPut = cmd.Execute(); 

    List lstResults = lstEmailOutPut.result; 
    string listID = lstResults[0]; // Got Precraeted List ID(Valid Confirmed) 

    Console.WriteLine("\n" + listID);     


    // compaign Create 
    campaignCreateOptions campaignCreateOpt = new campaignCreateOptions(); 
    campaignCreateOpt.list_id = listID; 
    campaignCreateOpt.subject = " New Campaign from dev_Anil"; 
    campaignCreateOpt.from_email = "[email protected]"; 
    campaignCreateOpt.from_name = "anil"; 

    Dictionary content = new Dictionary(); 
    content.Add("html", "Helloaasdsa"); 
    content.Add("text", "Hi all !! this is dev_anil"); 
    content.Add("url", ""); 
    content.Add("archive", ""); 

    campaignSegmentOptions csOptions = new campaignSegmentOptions(); 
    csOptions.match = "any"; // Could not set Condition -- need help for this 

    // Need to set a Dictionary typeOptions because null is not supported 
    Dictionary typeOptions = new Dictionary(); 

    campaignCreateParms campaignCreateParms = new campaignCreateParms(apiKey, EnumValues.campaign_type.auto, campaignCreateOpt, content, csOptions, typeOptions); 
    campaignCreateInput campaignCreateInput = new campaignCreateInput(campaignCreateParms); 
    campaignCreate campaignCreate = new campaignCreate(campaignCreateInput); 
    campaignCreateOutput ccOutput = campaignCreate.Execute(campaignCreateInput); 
    string abc = ccOutput.result; // This comes out to null 

} 
catch(Exception ee) 
{ 
    Console.WriteLine("\n\n Exception :" + ee.Message); // no exception 
} 

किसी को भी सही दिशा और क्या कोड के साथ गलत है दिखा सकते हैं:

यहां मेरे कोड का टुकड़ा है।

किसी भी मदद की बहुत सराहना की जाएगी।

धन्यवाद।

उत्तर

2

मैं इस समस्या का समाधान और यहाँ समाधान के रूप में कोड है। यहां MailID Mailchimp में आपके खाते में सूचीबद्ध सूची आईडी है।

 
private void CreateCampaignAndSend(string apiKey, string listID) 
{ 
      Int32 TemplateID = 100; 
      string campaignID =string.Empty;

// compaign Create Options campaignCreateOptions campaignCreateOpt = new campaignCreateOptions(); campaignCreateOpt.list_id = listID; campaignCreateOpt.subject = "subject"; campaignCreateOpt.from_email = "[email protected]"; campaignCreateOpt.from_name = "abc"; campaignCreateOpt.template_id = TemplateID; // Content Dictionary<string, string> content = new Dictionary<string, string>(); content.Add("html_ArticleTitle1", "ArticleTitle1"); content.Add("html_ArticleTitle2","ArticleTitle2"); content.Add("html_ArticleTitle3", "ArticleTitle3"); content.Add("html_Article1", "Article1"); content.Add("html_Article2", "Article2"); // Conditions List<campaignSegmentCondition> csCondition = new List<campaignSegmentCondition>(); campaignSegmentCondition csC = new campaignSegmentCondition(); csC.field = "interests-" + 123; // where 123 is the Grouping Id from listInterestGroupings() csC.op = "all"; csC.value = ""; csCondition.Add(csC); // Options campaignSegmentOptions csOptions = new campaignSegmentOptions(); csOptions.match = "all"; // Type Options Dictionary<string, string> typeOptions = new Dictionary<string, string>(); typeOptions.Add("offset-units", "days"); typeOptions.Add("offset-time", "0"); typeOptions.Add("offset-dir", "after"); // Create Campaigns campaignCreate campaignCreate = new campaignCreate(new campaignCreateInput(apiKey, EnumValues.campaign_type.plaintext, campaignCreateOpt, content, csOptions, typeOptions)); campaignCreateOutput ccOutput = campaignCreate.Execute(); List<Api_Error> error = ccOutput.api_ErrorMessages; // Catching API Errors if (error.Count <= 0) { campaignID = ccOutput.result; } else { foreach (Api_Error ae in error) { Console.WriteLine("\n ERROR Creating Campaign : ERRORCODE\t:" + ae.code + "\t ERROR\t:" + ae.error); } } }
एक नि: शुल्क accound मैं पाने पर
+0

: एल त्रुटि 506: Autoresponders मासिक पर ही उपलब्ध हैं और पे-के रूप में-यू-गो खातों। – Edd

+0

लेकिन मैं इसे इस कोड को जहां इस तरह तैयार है से नहीं मिल सकता है ... मैं typeOptions शब्दकोश के मूल्यों को निकाल दिया लेकिन उसे वहाँ से नहीं था .. – Edd

+0

हाय अनिल: campaignSegmentCondition मुझे त्रुटि मेरी संकलक vs'13 में पता चलता है। कृपया मुझे कुछ रास्ता दिखाएं :( –

1

मैं सामग्री से यूआरएल और संग्रह से हटा दिया। फिर अभियान ठीक बनाया गया था:

 // campaign Create 
     campaignCreateOptions campaignCreateOpt = new campaignCreateOptions(); 
     campaignCreateOpt.list_id = listId; 
     campaignCreateOpt.subject = " New Campaign from Someemone"; 
     campaignCreateOpt.from_email = "[email protected]"; 
     campaignCreateOpt.from_name = "someone"; 


     Dictionary<string, string> content = new Dictionary<string, string>(); 
     content.Add("html", "Lots of cool stuff here."); 


     campaignSegmentOptions csOptions = new campaignSegmentOptions(); 
     csOptions.match = "any"; // Could not set Condition -- need help for this 

     // Need to set a Dictionary typeOptions because null is not supported 
     Dictionary<string,string> typeOptions = new Dictionary<string, string>(); 

     campaignCreateParms campaignCreateParms = new campaignCreateParms(apiKey, EnumValues.campaign_type.trans, campaignCreateOpt, content, csOptions, typeOptions); 
     campaignCreateInput campaignCreateInput = new campaignCreateInput(campaignCreateParms); 
     campaignCreate campaignCreate = new campaignCreate(campaignCreateInput); 
     campaignCreateOutput ccOutput = campaignCreate.Execute(campaignCreateInput); 
     string newCampaignId = ccOutput.result; // Not null anymore 
संबंधित मुद्दे