如何使用 API 从 MailChimp 列表中提取订阅者计数?

发布于 2024-10-20 22:25:59 字数 1428 浏览 1 评论 0原文

我正在尝试使用他们的 API 显示 MailChimp 邮件列表中的订阅者计数,并且它已经部分工作,除了下面的代码当前正在吐出所有列表的订阅者计数,而不是一个特定列表的订阅者计数。我已在 $listId ='XXX'; 行中指定了列表 ID,但这似乎不起作用。因为我总共有五个列表,所以下面 PHP 的输出显示如下:

10 0 0 1 9

我需要在下面的代码中执行哪些操作才能从特定列表 ID 获取订阅者计数?

<?php
/**
This Example shows how to pull the Members of a List using the MCAPI.php 
class and do some basic error checking.
**/
require_once 'inc/MCAPI.class.php';

$apikey = 'XXX';
$listId = 'XXX';

$api = new MCAPI($apikey);

$retval = $api->lists();

if ($api->errorCode){
    echo "Unable to load lists()!";
    echo "\n\tCode=".$api->errorCode;
    echo "\n\tMsg=".$api->errorMessage."\n";
} else {
    foreach ($retval['data'] as $list){
        echo "\t ".$list['stats']['member_count'];
    }
}

?>

我刚刚遇到这个函数(见下文),它让我使用已知的 list_id 返回单个列表。问题是,我不确定如何在函数中添加 list_id 。

我假设我需要在这一行中定义它? $params["filters"] = $filters;

MailChimp lists() 方法文档可以参考这里:http://apidocs.mailchimp.com/rtfm/lists.func.php

    function lists($filters=array (
), $start=0, $limit=25) {
        $params = array();
        $params["filters"] = $filters;
        $params["start"] = $start;
        $params["limit"] = $limit;
        return $this->callServer("lists", $params);
    }

I'm trying to display the subscriber count from a MailChimp mailing list using their API, and I've got it partially working, except the code below is currently spitting out the subscriber count for all lists, rather than for one specific list. I've specified the list id in the line $listId ='XXX'; but that doesn't seem to be working. Because I have five lists in total, the output from the PHP below shows this:

10 0 0 1 9

What do I need to do in my code below to get the subscriber count from a specific list id?

<?php
/**
This Example shows how to pull the Members of a List using the MCAPI.php 
class and do some basic error checking.
**/
require_once 'inc/MCAPI.class.php';

$apikey = 'XXX';
$listId = 'XXX';

$api = new MCAPI($apikey);

$retval = $api->lists();

if ($api->errorCode){
    echo "Unable to load lists()!";
    echo "\n\tCode=".$api->errorCode;
    echo "\n\tMsg=".$api->errorMessage."\n";
} else {
    foreach ($retval['data'] as $list){
        echo "\t ".$list['stats']['member_count'];
    }
}

?>

I just came across this function (see below) that let's me return a single list using a known list_id. The problem is, I'm not sure how to add the list_id in the function.

I'm assuming I need to define it in this line? $params["filters"] = $filters;

The MailChimp lists() method documentation can be referred to here: http://apidocs.mailchimp.com/rtfm/lists.func.php

    function lists($filters=array (
), $start=0, $limit=25) {
        $params = array();
        $params["filters"] = $filters;
        $params["start"] = $start;
        $params["limit"] = $limit;
        return $this->callServer("lists", $params);
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空城缀染半城烟沙 2024-10-27 22:25:59

我强烈建议不要破坏包装器的内部结构,因为它不会像在线文档和包装器中包含的示例那样有用。使用包装器意味着在进行正确的调用时,您所追踪的行将被有效地填充。

不管怎样,这就是你想要的:

$filters = array('list_id'=>'XXXX');
$lists = $api->lists($filters);

I'd strongly recommend not mucking with the internals of the wrapper as it's not going to be nearly as helpful as the online documentation and the examples included with the wrapper. Using the wrapper means the line you tracked down will effectively be filled when make the proper call.

Anywho, this is what you want:

$filters = array('list_id'=>'XXXX');
$lists = $api->lists($filters);
墨洒年华 2024-10-27 22:25:59

Mailchimp 在其 api 周围提供了一个预构建的 php 包装器,位于 http://apidocs.mailchimp.com/downloads/ #php。此 api 包含一个函数lists(),根据其文档,该函数返回以下内容:

int member_count 给定列表中的活动成员数。

看起来这就是您上面提到的功能。您所要做的就是遍历返回的列表以找到具有正确 id 的列表。从那里您应该能够查询订户数量以及有关该列表的许多其他统计信息。

Mailchimp provides a pre-built php wrapper around their api at http://apidocs.mailchimp.com/downloads/#php. This api includes a function lists() which, according to its documentation, returns among other things:

int member_count The number of active members in the given list.

It looks like this is the function which you are referring to above. All you should have to do is iterate through the lists that are returned to find the one with the proper id. From there you should be able to query the subscriber count along with a number of other statistics about the list.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文