首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用Mailchimp

使用Mailchimp
EN

Stack Overflow用户
提问于 2014-06-13 23:41:27
回答 3查看 5.9K关注 0票数 6

我想在我的Mailchimp Node.js API应用程序中使用解析云托管为用户订阅邮件列表。解析不支持NPM,但是,考虑到Mailchimp没有依赖项,我想我可以将代码复制到我的项目中。但是,Mailchimp使用了Parse不支持的"https“模块。

有人知道怎么绕过这件事吗?

EN

回答 3

Stack Overflow用户

发布于 2014-06-13 23:41:27

我一直无法直接使用Mailchimp,但是REST非常容易使用。

main.js中,创建一个云函数。输入您的API键并更新REST以指向正确的邮件黑猩猩数据中心(http://apidocs.mailchimp.com/api/2.0/)。

代码语言:javascript
运行
复制
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)

代码语言:javascript
运行
复制
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");
    // ...
});
票数 9
EN

Stack Overflow用户

发布于 2015-04-10 07:48:00

  1. 在项目中安装mailchimp npm安装mailchimp-api
  2. 从客户端控制器调用具有所需数据的服务器控制器。 不要忘记将$http添加到控制器的顶部 $http({方法:'POST',url:‘/mailchimp/订阅’,data:{user:this.name}})。成功(函数(响应){ console.log("hai这是基本测试“+响应);$scope.send = response.message;}).error(函数(响应){ $scope.error = response.message;});
  3. 在服务器控制器中,将此添加到页的开头 var MailchimpUser = mongoose.model('MailchimpUser'),_=require(‘MailchimpUser’),mcapi = require('mailchimp-api');var apiKey =‘4bf6fb8820c333 da4179216c2c2ef8fb-US10’;//将此更改为您的键listID var = 'ebbf193760';var mc =新mcapi.Mailchimp(apiKey,{version:'2.0'}); 添加此功能 exports.subscribe =函数(req,res) { var条目= req.body.user;var mcReq ={ apikey:‘4bf6fb8820c333da4179216c2c2ef8fb-US10’,id:‘last 193760’,电子邮件:{email: entry + '@gmail.com'},merge_vars:{ FNAME:‘订户-名字’,LNAME:‘订户-姓氏’},'double_optin':false,‘’send_迎宾‘:true } //将订阅请求提交给电子邮件黑猩猩mc.lists.subscribe(mcReq,function(data) {console.log(Data));,函数(错误){console.log(错误);};};
  4. 添加此路由您的路由文件 App.route(‘/mailchimp/订阅’) .post(mailchimpUsers.subscribe);
票数 5
EN

Stack Overflow用户

发布于 2016-03-19 07:38:24

下面是我如何使用MailChimp APIv3.0使其工作,下面的方法支持添加/更新订阅服务器,以及向组中添加/移除订阅者!

先决条件:您需要一个MD5哈希方法来将用户的电子邮件转换为哈希。

  • 这是我用过的那个:http://www.webtoolkit.info/javascript-md5.html#.Vuz-yjZOwXV
  • 复制链接中的代码,并将其粘贴到新创建的文件中,例如,将其命名为"md5js.js“。
  • 更新您复制的代码,以便从exports.MD5 = function (string) {开始
  • 您可以测试从复制/粘贴模块获得的转换,方法是将结果与以下在线工具:http://www.miraclesalad.com/webtools/md5.php进行比较

代码语言:javascript
运行
复制
    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);
        }
      });
    });

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24215164

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档