将语言变量添加到 WWW::Mailchimp(订阅)

Adding language variable into WWW::Mailchimp (subscription)

我正在尝试弄清楚如何使用 WWW::Mailchimp ( http://search.cpan.org/~arcanez/WWW-Mailchimp/ ) 将某人注册到我们的列表中,同时指定语言人的(即英语,法语,德语,西班牙语等)。

这是我目前的情况:

my $mailchimp = WWW::Mailchimp->new(apikey => 'xxxx' );
   $mailchimp->listSubscribe( id => "xxx", email_address => $in->{Email}, merge_vars => [ FNAME => $name[0], LNAME => $name[1], mc_language => "fr", LANG => "fr", LANGUAGE => "fr" ] );

mc_language => "fr", LANG => "fr", LANGUAGE => "fr" 好像没有做任何事情(一直在尝试我看到的所有参数,徒劳地希望其中一个能起作用!)

虽然它有效(并要求您确认订阅),但所有语言变量都将被忽略。看了他们的文档,我有点迷茫,不知道该用什么:

https://apidocs.mailchimp.com/api/2.0/lists/subscribe.php

代码 "fr" 没问题,但我不确定要传递给它的参数是什么。

有没有人以前有过这方面的经验?除了语言,它工作正常(但我需要能够用他们自己的语言发送确认电子邮件,然后在发送邮件时也过滤掉)

更新: 好的,看起来更新到较新的 API 并不是一个简单的案例。我一直在研究 v3.0 API,它是对旧版本的彻底改造(新函数名称、发送请求的新方法等)。我要做的是研究 "Curl" 方法,这样我们至少可以让它继续下去。一旦完成,我可能会考虑编写一些代码以与 LWP::UserAgent 一起使用,因为这比执行大量 curl 请求更干净。遗憾的是,Perl 和 MailChimp(使用新的 API,甚至是 2.0 版!)

已经没有任何东西了

source来看,它默认为API 1.3:

has api_version => (
  is => 'ro',
  isa => Num,
  lazy => 1,
  default => sub { 1.3 },
);

您需要使用 shows 的文档 MC_LANGUAGE:

string MC_LANGUAGE Set the member's language preference. Supported codes are fully case-sensitive and can be found here.

看起来该模块只是将您提供的任何数据结构推送到 JSON 并将其发布到 Mailchimp,因此适合您目标 API 的 Mailchimp API 文档版本应该作为主要来源被引用。

好的,所以我终于到了!我一直在与 MailChimp 支持人员交谈,他们非常有帮助。原来这是一个双重问题。

1) 需要为相关列表启用自动翻译。这是他们对此的回答:

After taking a look at the call, it appears to be set up properly now, so you are all good on that front. That being said, I am seeing that the Auto-translate option doesn't seem to be enabled for any of your lists. In order for the Confirmation and all other response emails to automatically translate, this will need to be enabled for all of the lists being used.

We have a bit of additional information on that, here, if you'd like to check that out: http://kb.mailchimp.com/lists/signup-forms/translate-signup-forms-and-emails#Auto-Translate-Forms

2) 当通过API发起请求时,需要专门设置Accept-Language: xx值。例如en, fr, es, de等

这里有一个工作函数供以后需要的人使用。请务必更新 apikey、listId 和端点 URL.

do_register_email_list('foo@bar.com','Andrew Test',"en")

sub do_register_email_list {
# (email,name,lang)

    use WWW::Curl::Easy;
    use Digest::MD5;
    use JSON;

    my @name = split /\s+/, $_[1];
    my $apikey = 'xxxx-us6';
    my $listid = 'xxxx';
    my $email = $_[0];
    my $endpoint = "https://us6.api.mailchimp.com/3.0/lists";
    my $lang = $_[2]||'en';

    my $json = JSON::encode_json({
        'email_address' => $email,
        'status'        => 'pending',
        'language' => $lang,
        'merge_fields'  => {
            'FNAME'     => $name[0]||'',
            'LNAME'     => $name[1]||''
        }
    });

    my $curl = WWW::Curl::Easy->new;

    my $url = "$endpoint/$listid/members/" . Digest::MD5::md5(lc($email));

    $curl->setopt(CURLOPT_HEADER,1);
    $curl->setopt(CURLOPT_URL, $url);

#    $curl->setopt(CURLOPT_VERBOSE, 1);
    $curl->setopt(CURLOPT_USERPWD, 'user:' . $apikey);
    $curl->setopt(CURLOPT_HTTPHEADER, ['Content-Type: application/json',"Accept-Language: $lang"]);
    $curl->setopt(CURLOPT_TIMEOUT, 10);
    $curl->setopt(CURLOPT_CUSTOMREQUEST, 'PUT');
    $curl->setopt(CURLOPT_SSL_VERIFYPEER, 0);
    $curl->setopt(CURLOPT_POSTFIELDS, $json);

    # A filehandle, reference to a scalar or reference to a typeglob can be used here.
    my $response_body;
    $curl->setopt(CURLOPT_WRITEDATA,$response_body);

    # Starts the actual request
    my $retcode = $curl->perform;

#print "FOO HERE";
    # Looking at the results...
    if ($retcode == 0) {
        print "Transfer went ok\n";
        my $response_code = $curl->getinfo(CURLINFO_HTTP_CODE);
        print "Received response: $response_body\n";
    } else {
        # Error code, type of error, error message
        print "An error happened: $retcode ".$curl->strerror($retcode)." ".$curl->errbuf."\n";
    }
}

希望这能让其他人免于我对它的所有悲伤:)(MailChimp 支持女士还说她会让他们的团队在开发者说明中添加一些关于这个的东西,所以它更清楚一点!)