Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用ASP.Net在MailChimp中创建活动_C#_Asp.net_Mailchimp - Fatal编程技术网

C# 如何使用ASP.Net在MailChimp中创建活动

C# 如何使用ASP.Net在MailChimp中创建活动,c#,asp.net,mailchimp,C#,Asp.net,Mailchimp,我需要在MailChimp.com中创建并立即发送活动。为此,我使用了C#wrapperperceptive MCAPI.dll 从这个角度来看,很明显,我们不能列出,但可以创建活动。我尝试了代码,但是活动ID被返回为null;至少没有引发异常。我确实将活动类型设置为Auto 以下是我的代码片段: try { string apiKey = "api-us2"; // API KEY is valid string emailAddress = "ravinderpal.

我需要在
MailChimp.com
中创建并立即发送活动。为此,我使用了
C#wrapperperceptive MCAPI.dll

从这个角度来看,很明显,我们不能列出,但可以创建活动。我尝试了代码,但是
活动ID被返回为null
;至少没有引发异常。我确实将
活动类型设置为Auto

以下是我的代码片段:

try { string apiKey = "api-us2"; // API KEY is valid string emailAddress = "ravinderpal.singh@abc.net"; 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 = "anil.k@abc.net"; 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 } 尝试 { 字符串apiKey=“api-us2”;//api密钥有效 string emailAddress=“ravinderpal。singh@abc.net"; listsForEmailInput lstForEmailInput=新listsForEmailInput(apiKey,emailAddress); listsForEmail cmd=新listsForEmail(lstForemail输入); listsfremailoutput lstEmailOutPut=cmd.Execute(); List lstResults=lstEmailOutPut.result; 字符串listID=lstResults[0];//获取了预先划分的列表ID(已确认有效) Console.WriteLine(“\n”+listID); //合作创造 活动创建选项活动创建选项=新建活动创建选项(); ActivityCreateOpt.list_id=listID; ActivityCreateOpt.subject=“来自开发人员的新活动”; campaignCreateOpt.from_email=“anil。k@abc.net"; 活动CreateOpt.from_name=“anil”; 字典内容=新字典(); 添加(“html”、“Helloaasdsa”); 添加(“文本”,“大家好!!我是dev_anil”); 添加(“url”和“); 添加(“存档”和“); 活动分段选项csOptions=新的活动分段选项(); csOptions.match=“any”//无法设置条件--需要帮助吗 //需要设置字典类型选项,因为不支持null 字典类型选项=新建字典(); ActivityCreateParms-ActivityCreateParms=新的ActivityCreateParms(apiKey,EnumValues.campaign_type.auto,ActivityCreateOpt,content,csOptions,typeOptions); 活动CreateInput活动CreateInput=新的活动CreateInput(活动CreateParms); 活动创建=新建活动创建(活动创建输入); ActivityCreateOutput=ActivityCreate.Execute(ActivityCreateInput); 字符串abc=ccOutput.result;//结果为空 } 捕获(异常ee) { Console.WriteLine(“\n\n异常:+ee.Message);//无异常 } 谁能告诉我正确的方向和代码有什么问题吗

任何帮助都将不胜感激


谢谢。

我从内容中删除了url和存档。然后,该活动就很好地创建了:

       // 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
//活动创建
活动创建选项活动创建选项=新建活动创建选项();
ActivityCreateOpt.list_id=listId;
ActivityCreateOpt.subject=“来自SomeMone的新活动”;
活动CreateOpt.from_电子邮件=”someone@home.com";
活动CreateOpt.from_name=“someone”;
字典内容=新字典();
添加(“html”,“这里有很多很酷的东西。”);
活动分段选项csOptions=新的活动分段选项();
csOptions.match=“任意”//无法设置条件--需要帮助吗
//需要设置字典类型选项,因为不支持null
字典类型选项=新建字典();
ActivityCreateParms-ActivityCreateParms=新的ActivityCreateParms(apiKey,EnumValues.campaign_type.trans,ActivityCreateOpt,content,csOptions,typeOptions);
活动CreateInput活动CreateInput=新的活动CreateInput(活动CreateParms);
活动创建=新建活动创建(活动创建输入);
ActivityCreateOutput=ActivityCreate.Execute(ActivityCreateInput);
字符串newcampaid=ccOutput.result;//不再为空

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

私有void CreateActiveAndSend(字符串apiKey,字符串listID) { Int32 TemplateID=100; string活动ID=string.Empty

//compaign创建选项
活动创建选项活动创建选项=新建活动创建选项();
ActivityCreateOpt.list_id=listID;
活动创建opt.subject=“subject”;
活动CreateOpt.from_电子邮件=”abc@xyz.com";
活动CreateOpt.from_name=“abc”;
ActivityCreateOpt.template_id=TemplateID;
//内容
字典内容=新字典();
添加(“html_ArticleTitle1”、“ArticleTitle1”);
添加(“html_ArticleTitle2”、“ArticleTitle2”);
添加(“html_ArticleTitle3”、“ArticleTitle3”);
添加(“html_第1条”、“第1条”);
添加(“html_第2条”、“第2条”);
//条件
List csCondition=新列表();
ActivitySegmentCondition csC=新的ActivitySegmentCondition();
csC.field=“interests-”+123;//其中123是listInterestGroupings()中的分组Id
csC.op=“全部”;
csC.value=“”;
csCondition.Add(csC);
//选择权
活动分段选项csOptions=新的活动分段选项();
csOptions.match=“全部”;
//类型选项
字典类型选项=新建字典();
类型选项。添加(“抵销单位”、“天数”);
类型选项。添加(“偏移时间”,“0”);
类型选项。添加(“偏移方向”、“之后”);
//创建活动
活动创建活动创建=新建活动创建(新建活动创建输入(apiKey、EnumValues.campaign_type.plaintext、活动创建选项、内容、csOptions、类型选项));
ActivityCreateOutput=ActivityCreate.Execute();
List error=ccOutput.api\u ErrorMessages;//捕获api错误

if(error.Count on a free account i get:L error 506:自动应答器仅在每月和按量付费帐户上可用。但我无法从该代码中获取该设置在哪里…我删除了 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 = "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);

            }
        }

    }