使用MailChimp API v3和CURL

时间:2015-11-27 00:31:32

标签: php wordpress curl mailchimp mailchimp-api-v3.0

我想知道是否有人使用MailChimp API订阅用户到列表。

我想知道它是如何完成的,来自我想要完成的文档。

curl --request POST \
--url 'https://usX.api.mailchimp.com/3.0/lists' \
--user 'anystring:apikey' \
--header 'content-type: application/json' \
--data '{"name":"Freddie'\''s Favorite Hats","contact":{"company":"MailChimp","address1":"675 Ponce De Leon Ave NE","address2":"Suite 5000","city":"Atlanta","state":"GA","zip":"30308","country":"US","phone":""},"permission_reminder":"You'\''re receiving this email because you signed up for updates about Freddie'\''s newest hats.","campaign_defaults":{"from_name":"Freddie","from_email":"freddie@freddiehats.com","subject":"","language":"en"},"email_type_option":true}' \
--include

我的尝试是这样的:

$apiKey ='mykey';
$listID = 'id';
$email = 'my@email.com';
$data = array(
    'email_address' => $email,
    'status' => 'subscribed'
);

$body = json_encode($data);

$opts = array(
    'headers' => array(
        'Content-Type' => 'application/json',
        'Authorization' => 'apikey ' . $apiKey
    ),
    'body' => $body
);

$apiKeyParts = explode('-', $apiKey);
$shard = $apiKeyParts[1];

$url = '//' . $shard . '.api.mailchimp.com/3.0/lists/' . $listID . '/members/';

$response = wp_remote_post( $url, $opts );

if ( is_wp_error( $response ) ) {
    $result = $response->get_error_message();
} else {
    // DEBUG
    $result = print_r($response, true);
}

return $result;

然而它从来没有奏效,我还发现了另一篇文章(“我让这个工作”),但对我来说它是假的。

0 个答案:

没有答案