我想知道是否有人使用 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;
然而它从来没有奏效,我还发现另一篇文章说(“我得到了这个工作”)但对我来说它返回错误。