所需的一些基本Mailchimp API的例子 [英] Some basic Mailchimp API examples required

查看:2068
本文介绍了所需的一些基本Mailchimp API的例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来Mailchimp,需要一些帮助。

I'm new to Mailchimp and need some help.

使用基本的通讯注册表格...你只需嵌入一些prepackaged HTML到您的网页。但问题是,它不是很聪明。点击提交打开与Mailchimp URL等窗口(我不想重定向到MailChimp,我希望用户停留/点击提交后重定向到自己的网页。)

With their basic newsletter signup form... you simply embed some prepackaged HTML into your page. However the problem is that it's not very smart. Clicking on submit opens a window with a Mailchimp url, etc. (I don't want to redirect to MailChimp, I want the user to stay/redirect to my own page after hitting submit.)

他们提供了一个API和大量的文档,但没有太多有用的例子。该API应该允许我做我的网站全面融合,使讨厌的窗口不会在提交开拓。看来,当我看到他们的文档的东西,适用于我,我点击链接以获取更多的信息,我最终兜兜转转。他们告诉你如何做到这一点,但他们没有秀你怎么给它。我是一个成员,但显然你还需要知道一个秘密的握手,他们让你加入他们的支持论坛之前。

They provide an API and plenty of documentation but not too many useful examples. The API is supposed to allow me to do a full integration with my site so that pesky window doesn't open up on submission. It seems that when I read something in their docs that applies to me, I click the link to get more information and I end up going around in circles. They tell you how to do it but they fail to "show" you how to it. I'm a member but apparently you also need to know a secret handshake before they allow you to join their support forum.

大....这样我就可以得到一个API密钥,......他们有一大堆的文件和一大堆包装和放的;插件... PHP,Drupal的,字preSS等...

Great.... so I can get an API Key, ...they have tons of documentation and a whole bunch of wrappers & plugins... PHP, Drupal, Wordpress, etc...

用自己的pre-的打包解决方案的问题是,我只是用我的HTML,没有话语preSS,而不是PHP,Drupal的不是创造一个正常的网页...所以我只是不知道从哪里开始...我不知道如果我应该使用POST或GET。

The problem with using their pre-packaged solutions is that I just have a regular page I created with HTML, not Wordpress, not PHP, not Drupal... so I just don't know where to start ... I don't even know if I'm supposed to use POST or GET.

我不是一个新手到API的...我做的​​非常好,获得了谷歌地图API做我想做的事情。但是,谷歌提供了现实世界的工作示例除了自己详细的文档是怎么学的。我只是想看看它在行动之前,我可以掌握API的细节问题。

I'm not a newbie to API's... I do very well with getting the Google Maps API to do whatever I want. However, Google provides real-world working examples in addition to their detailed documentation which is how I learned it. I just want to see it in action before I can grasp the finer points of the API.

所以,哪里都是Mailchimp API的例子吗?一个简单的教程?只需使用API​​基本HTML注册表格?

So where are all the Mailchimp API examples? A simple tutorial? Just a basic HTML signup form using the API?

感谢 - 你对任何人都可以点我在正确的方向!

Thank-you to anyone that can point me in the right direction!

推荐答案

编辑:由于张贴这个答案MailChimp发布了他们的API的版本2。直到我有机会测试它,这个答案将只包含API版本1的例子。

Since posting this answer MailChimp has released version 2 of their API. Until I have a chance to test it, this answer will only contain the example for API version 1.

摸索了一段时间后,我发现使用与jQuery的PHP示例站点。从我能够与包含基本的注册表单的jQuery创建一个简单的HTML页面。 PHP的文件是在用户永远看不到它们尚未jQuery的仍然可以访问和放大器背景隐藏;使用。

After fumbling around for a while, I found a site using the PHP example with jQuery. From that I was able to create a simple HTML page with jQuery containing the basic sign-up form. The PHP files are "hidden" in the background where the user never sees them yet the jQuery can still access & use.

1)下载PHP 5 jQuery的例子在这里...(修改:链接都死了不过,唯一的重要组成部分,是PHP官方的API包装这是可以的这里。)

1) Download the PHP 5 jQuery example here... (EDIT: links are dead. However, the only important part is the official API wrapper for PHP which is available here.)

http://apidocs.mailchimp.com/downloads /mcapi-simple-subscribe-jquery.zip

如果你只有PHP 4,只需下载MCAPI 1.2版本,并更换相应 MCAPI.class.php 文件之上。

If you only have PHP 4, simply download version 1.2 of the MCAPI and replace the corresponding MCAPI.class.php file above.

http://apidocs.mailchimp.com /downloads/mailchimp-api-class-1-2.zip

2)通过在适当位置增加你的API密钥和列表的ID在存储address.php 文件按照自述文件中的指示。

2) Follow the directions in the Readme file by adding your API key and List ID to the store-address.php file at the proper locations.

3)您可能还需要收集用户的姓名和/或其它信息。您可以选择使用相应的合并变量添加一个数组到存储address.php 文件。

3) You may also want to gather your users' name and/or other information. You have to add an array to the store-address.php file using the corresponding Merge Variables.

下面是我的存储address.php 文件看起来像在这里我也收集姓,名和电子邮件类型:

Here is what my store-address.php file looks like where I also gather the first name, last name, and email type:

<?php

function storeAddress(){

    require_once('MCAPI.class.php');  // same directory as store-address.php

    // grab an API Key from http://admin.mailchimp.com/account/api/
    $api = new MCAPI('123456789-us2');

    $merge_vars = Array( 
        'EMAIL' => $_GET['email'],
        'FNAME' => $_GET['fname'], 
        'LNAME' => $_GET['lname']
    );

    // grab your List's Unique Id by going to http://admin.mailchimp.com/lists/
    // Click the "settings" link for the list - the Unique Id is at the bottom of that page. 
    $list_id = "123456a";

    if($api->listSubscribe($list_id, $_GET['email'], $merge_vars , $_GET['emailtype']) === true) {
        // It worked!   
        return 'Success!&nbsp; Check your inbox or spam folder for a message containing a confirmation link.';
    }else{
        // An error ocurred, return error message   
        return '<b>Error:</b>&nbsp; ' . $api->errorMessage;
    }

}

// If being called via ajax, autorun the function
if($_GET['ajax']){ echo storeAddress(); }
?>

4)创建的HTML / CSS / jQuery的形式。它并不需要是一个PHP页面上。

4) Create your HTML/CSS/jQuery form. It is not required to be on a PHP page.

下面是我的 index.html的文件看起来是这样的:

Here is what my index.html file looks like:

<form id="signup" action="index.html" method="get">
    <input type="hidden" name="ajax" value="true" />
    First Name: <input type="text" name="fname" id="fname" />
    Last Name: <input type="text" name="lname" id="lname" />
    email Address (required): <input type="email" name="email" id="email" />
    HTML: <input type="radio" name="emailtype" value="html" checked="checked" />
    Text: <input type="radio" name="emailtype" value="text" />
    <input type="submit" id="SendButton" name="submit" value="Submit" />
</form>
<div id="message"></div>

<script src="jquery.min.js"></script>
<script>
$(document).ready(function() {
    $('#signup').submit(function() {
        $("#message").html("Adding your email address...");
        $.ajax({
            url: 'inc/store-address.php', // proper url to your "store-address.php" file
            data: $('#signup').serialize(),
            success: function(msg) {
                $('#message').html(msg);
            }
        });
        return false;
    });
});
</script>

所需的片...


  • 的index.html 的构造如上述或相似。使用jQuery,外观和选项是无止境的。

  • index.html constructed as above or similar. With jQuery, the appearance and options are endless.

存储address.php 文件下载为对Mailchimp网站PHP例子一部分,并与您的 API KEY修改 LIST ID 。您需要将其他可选字段添加到阵列中。

store-address.php file downloaded as part of PHP examples on Mailchimp site and modified with your API KEY and LIST ID. You need to add your other optional fields to the array.

MCAPI.class.php 的文件从Mailchimp网站下载(版本1.3 PHP 5或1.2版本的PHP 4)。将其放置在同一目录下的存储address.php 或你必须更新商店address.php内的URL路径,因此它可以找到它。

MCAPI.class.php file downloaded from Mailchimp site (version 1.3 for PHP 5 or version 1.2 for PHP 4). Place it in the same directory as your store-address.php or you must update the url path within store-address.php so it can find it.

这篇关于所需的一些基本Mailchimp API的例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆