【发布时间】: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,新地址还是没有。
【问题讨论】:
标签: ios objective-c parse-platform mailchimp mandrill