adrian7 / mailchimp-api-v3
Mailchimp API版本3的简单封装
Requires
- php: >=5.6.0
- guzzlehttp/guzzle: ~6.0
Requires (Dev)
- phpspec/phpspec: ~2.2
This package is not auto-updated.
Last update: 2024-09-21 00:42:38 UTC
README
安装
composer require adrian7/mailchimp-api-v3
用法
有一种方法可以统治它们所有
// $arguments is used as POST data or GET parameters, depending on the method used. request($resource, $arguments = [], $method = 'GET')
但它足够聪明,可以将这些调用也映射过来
get($resource, array $options = []) head($resource, array $options = []) put($resource, array $options = []) post($resource, array $options = []) patch($resource, array $options = []) delete($resource, array $options = [])
分页
我们使用查询字符串中的 offset
和 count
来分页数据,因为它提供了对如何查看数据的更大控制。Offset 默认为 0,因此如果您使用 offset=1,您将错过数据集中的第一个元素。Count 默认为 10。
来源:http://kb.mailchimp.com/api/article/api-3-overview
过滤
大多数端点目前不支持过滤,但我们计划在未来添加这些功能。模式将告诉您哪些集合可以过滤,以及需要在查询字符串中包含什么。
来源:http://kb.mailchimp.com/api/article/api-3-overview
部分响应
为了减少数据传输,请在查询字符串中传递一个逗号分隔的字段列表,以包括或排除特定响应中的字段。参数 fields
和 exclude_fields
是互斥的,并且如果请求中字段无效,将会抛出错误。
来源:http://kb.mailchimp.com/api/article/api-3-overview
代理后
如果您在代理后面,您可以直接在类上使用 setProxy
。
setProxy(host : string, port : int, [ssl : bool = false], [username = null], [password = null]);
请参阅 示例。
示例
所有查询都将返回一个包含解析的json响应的对象。
$mc = new Mailchimp('<api-key>', '<guzzle-options[array]>'); // Get 10 lists starting from offset 10 and include only a specific set of fields $result = $mc->request('lists', [ 'fields' => 'lists.id,lists.name,lists.stats.member_count', 'offset' => 10, 'count' => 10 ]); // Will fire this query: // GET https://us1.api.mailchimp.com/3.0/lists?fields=lists.id,lists.name,lists.stats.member_count&count=10 var_dump($result);
创建列表
// All these fields are required to create a new list. $result = $mc->post('lists', [ 'name' => 'New list', 'permission_reminder' => 'You signed up for updates on mailchimp-api-v3.', 'email_type_option' => false, 'contact' => [ 'company' => 'Doe Ltd.', 'address1' => 'DoeStreet 1', 'address2' => '', 'city' => 'Doesy', 'state' => 'Doedoe', 'zip' => '1672-12', 'country' => 'US', 'phone' => '55533344412' ], 'campaign_defaults' => [ 'from_name' => 'John Doe', 'from_email' => 'john@doe.com', 'subject' => 'My new campaign!', 'language' => 'US' ] ]);
子资源
$result = $mc->get('lists/e04d611199', [ 'fields' => 'id,name,stats.member_count' ]);
代理
$mc->setProxy('https://127.0.0.1', 10, true, 'username', 'password'); $result = $mc->get('lists/e04d611199', [ 'fields' => 'id,name,stats.member_count' ]);
更多文档
您应该阅读Mailchimp API v3的 文档。