classy-org / mailchimp-api-php-client
此包的最新版本(1.0.2)没有可用的许可证信息。
Mailchimp API v3.0 的简单封装,用于与 Guzzle Http Client 交互
1.0.2
2016-12-09 15:04 UTC
Requires
- guzzlehttp/guzzle: 6.*
This package is not auto-updated.
Last update: 2024-09-28 19:36:30 UTC
README
Mailchimp API v3.0 的简单封装,用于与 Guzzle Http Client 交互
安装
可以使用 Composer 安装 Mailchimp API php 客户端
composer require classy-org/mailchimp-api-php-client
确保您已在您的应用程序中包含 composer 自动加载器
require_once '/path/to/your/project/vendor/autoload.php';
使用方法
// Instantiate the client $client = new \Classy\MailchimpClient('dc834647d7f8a38c86b25dd4fdeff6f7-us2'); // use your mailchimp API key here // Fetches your mailchimp lists $httpResponse = $client->get('/lists'); $lists = json_decode($httpResponse->getBody()->getContents()); // Or shorter: $lists = $client->getData('/lists');
异常处理
此客户端使用 Guzzle Http client。当 Http 响应不是 200(OK)时,将抛出异常
try { $response = $client->get('/lists/e87ab1c34'); } catch (Exception $e) { if ($e instanceof \GuzzleHttp\Exception\ConnectException) { // there was a networking error } if ($e instanceof \GuzzleHttp\Exception\ClientException) { // Mailchimp API returned a 4xx response. $httpStatusCode = $e->getCode(); if ($httpStatusCode == 404) { // resource doesn't exist } if ($httpStatusCode == 401) { // you're unauthorized (api key must be invalid) } if ($httpStatusCode == 403) { // you're not allowed to request this endpoint } if ($httpStatusCode == 400) { // body payload is invalid } if (...) { // } $bodyResponse = $e->getResponse()->getBody()->getContents(); } if ($e instanceof \GuzzleHttp\Exception\ServerException) { // Mailchimp returned a 5xx response, which means they experience technical difficulties. } }