我正在使用 Brandon Seydel 的 MailChimp.Net.V3(此软件包的版本 4)。我正在尝试使用以下代码添加成员(member)标签
using MailChimp.Net;
private async Task MaintainTagsAsync()
{
string apikey = "<apikey>";
string listid = "<listid>";
string emailaddress = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="077f477f2964686a" rel="noreferrer noopener nofollow">[email protected]</a>";
try {
MailChimpManager Mcm = new MailChimpManager(apikey);
Member m = await Mcm.Members.GetAsync(listid, emailaddress);
m.Tags.Add(new MemberTag
{
Name = "MyTag"
});
m.TagsCount = +1;
await Mcm.Members.AddOrUpdateAsync(listid, m);
}
catch (Exception e) {}
}
上面的代码看起来执行正常,但是当我检查成员时,我发现标签尚未添加。我尝试过增加和不增加 TagsCount 属性,结果相同。
有谁有使用此功能的经验,并且可以指出我哪里出错了。
最佳答案
我现在找到了一种似乎有效的方法。请看下面的代码:
using MailChimp.Net;
private async Task MaintainTagsAsync()
{
string apikey = "<apikey>";
string listid = "<listid>";
string emailaddress = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="710931095f121e1c" rel="noreferrer noopener nofollow">[email protected]</a>";
try {
MailChimpManager Mcm = new MailChimpManager(apikey);
Member m = await Mcm.Members.GetAsync(listid, emailaddress);
Tags tags = new Tags();
tags.MemberTags.Add(new Tag() {
Name = "MyTag",
Status = "active"
});
await Mcm.Members.AddTagsAsync(listId, emailaddress, tags);
}
catch (Exception e) {}
}
关于c# - 将标签添加到 MailChimp 成员对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56025504/