5

でキャンペーンを作成してすぐに送信する必要がありますMailChimp.com。この目的で使用しました。 C# wrapper Percepective MCAPI.dll

MailChimp APIから、リストを作成することはできませんが、キャンペーンを作成できることは明らかです。コードを試しましたが、campaignID is retured null; 少なくとも例外はスローされません。を設定しましたcampaigntype to Auto

ここに私のコードスニペットがあります:

試す
{
     文字列 apiKey = "api-us2"; // API KEY は有効です
     string emailAddress = "ravinderpal.singh@abc.net";
     listForEmailInput lstForEmailInput = new listsForEmailInput(apiKey, emailAddress);
     listForEmail cmd = new listsForEmail(lstForEmailInput);
     listsForEmailOutput lstEmailOutPut = cmd.Execute();

     リスト lstResults = lstEmailOutPut.result;
     文字列 listID = lstResults[0]; // 事前に作成されたリスト ID を取得 (有効確認済み)

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


     // キャンペーンの作成
     キャンペーン作成オプション キャンペーン作成オプト = 新しいキャンペーン作成オプション();
     CampaignCreateOpt.list_id = listID;
     CampaignCreateOpt.subject = "dev_Anil からの新しいキャンペーン";
     CampaignCreateOpt.from_email = "anil.k@abc.net";
     CampaignCreateOpt.from_name = "anil";

     辞書の内容 = 新しい Dictionary();
     content.Add("html", "Helloaasdsa");
     content.Add("text", "こんにちは!!dev_anilです");
     content.Add("url", "");
     content.Add("アーカイブ", "");

     CampaignSegmentOptions csOptions = new CampaignSegmentOptions();
     csOptions.match = "任意"; // 条件を設定できませんでした -- これについては助けが必要です

     // null がサポートされていないため、Dictionary typeOptions を設定する必要があります
     Dictionary typeOptions = new Dictionary();

     CampaignCreateParms CampaignCreateParms = new CampaignCreateParms(apiKey, EnumValues.campaign_type.auto, CampaignCreateOpt, content, csOptions, typeOptions);
     CampaignCreateInput キャンペーンCreateInput = 新しいキャンペーンCreateInput(campaignCreateParms);
     キャンペーンの作成 キャンペーンの作成 = 新しいキャンペーンの作成(キャンペーンの作成入力);
     CampaignCreateOutput ccOutput = CampaignCreate.Execute(campaignCreateInput);
     文字列 abc = ccOutput.result; // これは null になります

}
 catch(例外 ee)
{
     Console.WriteLine("\n\n 例外:" + ee.Message); // 例外なし
}

誰でも正しい方向とコードの何が問題なのかを教えてもらえますか?

どんな助けでも大歓迎です。

ありがとう。

4

2 に答える 2

2

私はこの問題を解決しました、そしてここに解決策としてのコードがあります。ここでlistIDは、Mailchimpのアカウントに事前に作成されたリストIDです。

private void CreateCampaignAndSend(string apiKey、string listID)
{{
            Int32 TemplateID = 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); } } }
于 2011-09-01T13:40:27.723 に答える
1

コンテンツから 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
于 2011-06-23T13:07:24.930 に答える