【问题标题】:How to Create a campaign in MailChimp using ASP.Net如何使用 ASP.Net 在 MailChimp 中创建活动
【发布时间】:2011-09-17 03:20:52
【问题描述】:

我需要在MailChimp.com 中创建并立即发送活动。我为此使用了 C# wrapper <strong>Percepective MCAPI.dll</strong>

来自MailChimp API,很明显我们不能列出但可以创建活动。我尝试了代码,但 <strong>campaignID is retured null</strong>;至少没有抛出异常。我确实设置了campaigntype to Auto

这是我的代码 sn-p:

尝试 { 字符串 apiKey = "api-us2"; // API KEY 有效 字符串 emailAddress = "ravinderpal.singh@abc.net"; listsForEmailInput lstForEmailInput = new listsForEmailInput(apiKey, emailAddress); listsForEmail cmd = 新的 listsForEmail(lstForEmailInput); listsForEmailOutput lstEmailOutPut = cmd.Execute(); 列出 lstResults = lstEmailOutPut.result; 字符串列表 ID = lstResults[0]; // 得到 Precraeted List ID( Valid Confirmed ) Console.WriteLine("\n" + listID); // 竞争创建 campaignCreateOptionscampaignCreateOpt = 新的campaignCreateOptions(); campaignCreateOpt.list_id = listID; campaignCreateOpt.subject = "来自 dev_Anil 的新广告系列"; campaignCreateOpt.from_email = "anil.k@abc.net"; campaignCreateOpt.from_name = "anil"; 字典内容 = new Dictionary(); content.Add("html", "Helloaasdsa"); content.Add("text", "大家好!!这是dev_anil"); content.Add("url", ""); content.Add("存档", ""); campaignSegmentOptions csOptions = 新的campaignSegmentOptions(); csOptions.match = "任何"; // 无法设置条件 - 需要帮助 // 需要设置一个 Dictionary typeOptions 因为不支持 null 字典 typeOptions = new Dictionary(); campaignCreateParmscampaignCreateParms = newcampaignCreateParms(apiKey, EnumValues.campaign_type.auto,campaignCreateOpt, content, csOptions, typeOptions); campaignCreateInputcampaignCreateInput = newcampaignCreateInput(campaignCreateParms); 活动创建活动创建 = 新活动创建(活动创建输入); campaignCreateOutput ccOutput =campaignCreate.Execute(campaignCreateInput); 字符串 abc = ccOutput.result; // 结果为 null } 捕获(异常 ee) { Console.WriteLine("\n\n 异常:" + ee.Message); // 没有例外 }

谁能告诉我正确的方向和代码有什么问题。

任何帮助将不胜感激。

谢谢。

【问题讨论】:

    标签: c# asp.net mailchimp


    【解决方案1】:

    我解决了这个问题,这里是代码作为解决方案。这里的 listID 是您在 Mailchimp 中的帐户中预先创建的 List ID。

    私人无效 CreateCampaignAndSend(字符串 apiKey,字符串 listID) { Int32 模板 ID = 100; 字符串campaignID =string.Empty; // compaign Create Options campaignCreateOptions campaignCreateOpt = new campaignCreateOptions(); campaignCreateOpt.list_id = listID; campaignCreateOpt.subject = "subject"; campaignCreateOpt.from_email = "abc@xyz.com"; 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); } } }

    【讨论】:

    • 在免费帐户上我得到:L 错误 506:自动回复器仅适用于每月和即用即付帐户。
    • 但是我无法从这个代码中得到它这个集合在哪里......我删除了 typeOptions 字典的值,但它不是来自那里......
    • hi anil:campaignSegmentCondition 在我的编译器 vs'13 中显示错误。请告诉我一些路径:(
    【解决方案2】:

    我从内容中删除了网址和存档。然后就很好地创建了广告系列:

           // campaign Create
            campaignCreateOptions campaignCreateOpt = new campaignCreateOptions();
            campaignCreateOpt.list_id = listId;
            campaignCreateOpt.subject = " New Campaign from Someemone";
            campaignCreateOpt.from_email = "someone@home.com";
            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
    

    【讨论】:

      猜你喜欢
      • 2015-10-04
      • 2019-10-20
      • 2011-05-07
      • 2015-09-19
      • 2015-12-01
      • 2018-12-03
      • 2018-05-08
      • 2016-12-22
      • 2016-01-11
      相关资源
      最近更新 更多