我想在我的Mailchimp Node.js API应用程序中使用解析云托管为用户订阅邮件列表。解析不支持NPM,但是,考虑到Mailchimp没有依赖项,我想我可以将代码复制到我的项目中。但是,Mailchimp使用了Parse不支持的"https“模块。
有人知道怎么绕过这件事吗?
发布于 2014-06-13 23:41:27
我一直无法直接使用Mailchimp,但是REST非常容易使用。
在main.js中,创建一个云函数。输入您的API键并更新REST以指向正确的邮件黑猩猩数据中心(http://apidocs.mailchimp.com/api/2.0/)。
var mailchimpApiKey = "<<REPLACE_WITH_YOUR_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://<<REPLACE_WITH_DATA_CENTRE>>.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);
}
});
});然后,在调用这个函数的代码中.(替换列表ID)
Parse.Cloud.run("SubscribeUserToMailingList", {
listid : "<<REPLACE_WITH_LIST_ID>>",
email : email,
mergevars : {
FNAME : firstName,
LNAME : lastName
}
})
.then(function(success){
console.log("Successfully subscribed");
// ...
},
function(error){
console.log("Unable to subscribe");
// ...
});发布于 2015-04-10 07:48:00
$http添加到控制器的顶部
$http({方法:'POST',url:‘/mailchimp/订阅’,data:{user:this.name}})。成功(函数(响应){ console.log("hai这是基本测试“+响应);$scope.send = response.message;}).error(函数(响应){ $scope.error = response.message;});发布于 2016-03-19 07:38:24
下面是我如何使用MailChimp APIv3.0使其工作,下面的方法支持添加/更新订阅服务器,以及向组中添加/移除订阅者!
先决条件:您需要一个MD5哈希方法来将用户的电子邮件转换为哈希。
exports.MD5 = function (string) {开始
var jsmd5 = require('cloud/md5js.js');
// here replace that with your own data center (by looking at your API key).
var datacenter = "us13";
var MAILCHIMP_URL = "https://<any_string>:<apikey>@" + datacenter + ".api.mailchimp.com/3.0/";
var MAILCHIMP_LIST_NEWSLETTER_ID = <yourlistId>;
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 email = request.params.email;
var firstName = request.params.firstname;
var lastName = request.params.lastname;
// this converts the email string into an MD5 hash.
// this is Required if you want to use a "PUT" which allows add/update of an entry, compared to the POST that allows only adding a new subscriber.
var emailHash = jsmd5.MD5(email);
var mailchimpData = {
'email_address': email,
'status': "subscribed",
'merge_fields': {
'FNAME': firstName,
'LNAME': lastName
},
'interests': {
"<groupID>": true // optional, if you want to add the user to a "Group".
}
};
var url = MAILCHIMP_URL + "lists/" + MAILCHIMP_LIST_NEWSLETTER_ID + "/members/" + emailHash;
// using a "PUT" allows you to add/update an entry.
Parse.Cloud.httpRequest({
method: 'PUT',
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);
}
});
});
https://stackoverflow.com/questions/24215164
复制相似问题