getLastError() public method

If something didn't work, this should contain the string describing the problem.
public getLastError ( ) : array | false
return array | false describing the error
示例#1
1
<?php

require "../vendor/autoload.php";
use DrewM\MailChimp\MailChimp;
$MailChimp = new MailChimp('255970dd153fe7b1d83bec1478cbaa74-us11');
$result = $MailChimp->get('lists');
// Mailing List
// $list_id = '5c6bd183d4';
// Simpleblend Blog
$list_id = '53f4059701';
$result = $MailChimp->post("lists/{$list_id}/members", ['email_address' => '*****@*****.**', 'status' => 'subscribed']);
if ($MailChimp->success()) {
    print_r($result);
} else {
    echo $MailChimp->getLastError();
}
// require_once 'inc/MCAPI.class.php';
// $api = new MCAPI('[[YOUR_API_KEY]]');
// $merge_vars = array('FNAME'=>$_POST["fname"], 'LNAME'=>$_POST["lname"]);
//
// // Submit subscriber data to MailChimp
// // For parameters doc, refer to: http://apidocs.mailchimp.com/api/1.3/listsubscribe.func.php
// $retval = $api->listSubscribe( '[[YOUR_LIST_ID]]', $_POST["email"], $merge_vars, 'html', false, true );
//
// if ($api->errorCode){
//   echo "<h4>Please try again.</h4>";
//
// } else {
//   echo "<h4>Thank you, you have been added to our mailing list.</h4>";
//
// }
示例#2
0
 /**
  * Make a request to the Mailchimp API.
  *
  * @param  string $method   Request method (get, post, patch etc)
  * @param  string $endpoint Endpoint URL (e.g 'lists')
  * @param  array  $args     Request arguments
  * @return array            Response data
  *
  * @throws \Exception On error
  */
 private function request($method, $endpoint, $args = [])
 {
     $data = $this->mc->{$method}($endpoint, $args, 5);
     $response = $this->mc->getLastResponse();
     if (isset($response['headers']['http_code'])) {
         switch (substr($response['headers']['http_code'], 0, 1)) {
             case '4':
                 throw new Exception($data['title'] . ': ' . $data['detail']);
             case '5':
                 throw new Exception('Mailchimp API 500 error. Service may be unavailable.');
             default:
                 return $data;
         }
     } else {
         throw new Exception('Unknown Mailchimp error: ' . $this->mc->getLastError());
     }
 }
示例#3
0
 /**
  * @return bool
  */
 public function lastActionSucceeded()
 {
     return !$this->mailChimp->getLastError();
 }