3

我编写了以下代码来从我的 MailChimp 帐户中获取列表及其组,并使用 PerceptiveMCAPI 在多个组下订阅用户。我可以毫无问题地订阅组,而我无法从特定组中删除用户。我尝试同时使用 listUpdateMember 和 update_existing 属性,但没有任何效果。

这是代码:

public partial class Signup : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.GetList();
        }

    }

    protected void btnSubscribe_Click(object sender, EventArgs e)
    {
        Dictionary<string, object> dic = new Dictionary<string, object>();
        List<interestGroupings> lst = new List<interestGroupings>();           
        for (int i = 0; i <= chkGroups.Items.Count - 1;i++ )
        {
            if (chkGroups.Items[i].Selected)
            {
                lst.Add(new interestGroupings { id = Convert.ToInt32(chkGroups.Items[i].Value), name = chkGroups.Items[i].Text, groups = new List<string> { chkGroups.Items[i].Text } });
            }
        }
        dic.Add("GROUPINGS", lst);            

        listSubscribeParms param = new listSubscribeParms();
        param.email_address = txtEmail.Text;
        param.email_type = EnumValues.emailType.html;
        param.apikey = MCAPISettings.default_apikey;
        param.id = drpList.SelectedValue;
        param.merge_vars = dic;
        //param.update_existing = true;
        listSubscribeInput subInput = new listSubscribeInput(param);
        listSubscribe sub = new listSubscribe(subInput);
        listSubscribeOutput subOutput = sub.Execute();
        if (subOutput.result)
            Response.Write("Congrats! a confirmation email has been sent to your email id");
        else
        {
            listUpdateMemberParms upparam = new listUpdateMemberParms(MCAPISettings.default_apikey,param.id, param.email_address, param.merge_vars, EnumValues.emailType.html,true);
            this.UpdateMember(upparam);
        }
    }

    private void UpdateMember(listUpdateMemberParms param)
    {            
        listMemberInfoInput memInput = new listMemberInfoInput(MCAPISettings.default_apikey, param.id, param.email_address);
        listMemberInfo memInfo = new listMemberInfo();
        listMemberInfoOutput memOutput = memInfo.Execute(memInput);

        param.email_address = memOutput.result.id;
        param.replace_interests = true;

        listUpdateMemberInput upInput = new listUpdateMemberInput(param);
        listUpdateMember update = new listUpdateMember(upInput);
        listUpdateMemberOutput output = update.Execute();
        if (output.result)
            Response.Write("Congrats! your details has been updated");
        else
        {
            Response.Write("Sorry! it seems you already exist in our database.");
        }
    }

    private void GetList()
    {
        // Code to get the list and add it to Dropdown list
    }
    private void GetGroups()
    {
        //Code to get groups under a list and adding it to check box
    }       

}

请帮我。

问候, 阿鲁尔

4

0 回答 0