从 iOS 应用程序订阅电子邮件地址到 MailChimp
Posted
技术标签:
【中文标题】从 iOS 应用程序订阅电子邮件地址到 MailChimp【英文标题】:Subscribing email address to MailChimp from iOS app 【发布时间】:2015-01-29 23:35:46 【问题描述】:我在我的应用中添加了一个联系表单,允许用户通过电子邮件直接向我发送反馈。我正在使用 Mandrill 和 Parse,效果很好!
联系表单上有一个“将我添加到邮件列表...”选项,如果选中此选项,我正在寻找一种将用户的电子邮件自动添加到 MailChimp 的方法。
我知道 Objective C 可以通过包装器访问 MailChimp API,但我想知道是否没有更直接的方法可以简单地将电子邮件添加到 ios/Objective C 中的 MailChimp 邮件列表?
感谢阅读。
编辑 #1:取得进展,但尚未成功。
1) 我已将 answer 中的云代码添加到 Parse(替换为两个键,其中 KEY2 是 MailChimp 键的最后三个字符):
var mailchimpApiKey = "MY_MAILCHIMP_KEY";
Parse.Cloud.define("subscribeUserToMailingList", function(request, response)
if (!request.params ||
!request.params.email)
response.error("Must supply email address, firstname and lastname to Mailchimp signup");
return;
var mailchimpData =
apikey : mailchimpApiKey,
id : request.params.listid,
email :
email : request.params.email
,
merge_vars : request.params.mergevars
var url = "https://KEY2.api.mailchimp.com/2.0/lists/subscribe.json";
Parse.Cloud.httpRequest(
method: 'POST',
url: url,
body: JSON.stringify(mailchimpData),
success: function(httpResponse)
console.log(httpResponse.text);
response.success("Successfully subscribed");
,
error: function(httpResponse)
console.error('Request failed with response code ' + httpResponse.status);
console.error(httpResponse.text);
response.error('Mailchimp subscribe failed with response code ' + httpResponse.status);
);
);
2) 我已将此 Objective-C 代码添加到我的 iOS 项目中(添加到我的 MailChimp 列表 ID):
[PFCloud callFunctionInBackground:@"subscribeUserToMailingList" withParameters:@@"listid":@"MY_LIST_ID",@"email":userEmail,@"mergevars":@@"FNAME":firstName,@"LNAME":lastName
block:^(NSString *result, NSError *error)
if (error)
//error
else
];
结果?这个错误:
Error Domain=Parse Code=141 "The operation couldn’t be completed. (Parse error 141.)" … error=Mailchimp subscribe failed with response code 500, code=141
编辑 #2:更多进展,但尚未成功。
上一个错误是由于尝试将电子邮件地址添加到已经存在的邮件列表而导致的。我现在没有收到任何错误,并且在上面的块中出现“已成功订阅”result
。但是,登录MailChimp,新地址还是没有。
【问题讨论】:
【参考方案1】:好的,结果代码没问题!请使用、分享和享受。
问题是 MailChimp(聪明地)需要双重选择加入邮件列表。
第一个选择加入使用特定的userEmail
运行此代码,这会导致向您的待添加用户发送一封电子邮件。
电子邮件要求他们确认订阅,如果他们这样做(这是电子邮件中的链接),这就是第二次选择加入。然后,他们的电子邮件将添加到您的列表中。
因此,底线是代码不会自动将用户添加到您的邮件列表中——仍然需要他们的确认。这是确保您的邮件列表中的人确实想在那里(即有机会阅读您的电子邮件)的好方法!
【讨论】:
以上是关于从 iOS 应用程序订阅电子邮件地址到 MailChimp的主要内容,如果未能解决你的问题,请参考以下文章
使用 mailcore (iOS),我如何从特定电子邮件地址获取所有电子邮件?