MailChimp API在V3.0 PHP Curl中响应404
我正在使用以下代码启动一个成员添加请求到MailChimp中的列表MailChimp API在V3.0 PHP Curl中响应404,php,curl,mailchimp,mailchimp-api-v3.0,Php,Curl,Mailchimp,Mailchimp Api V3.0,我正在使用以下代码启动一个成员添加请求到MailChimp中的列表 <?php error_reporting(-1); ini_set('display_errors', 1); $email = 'test@domain.com'; $first_name = 'name'; $last_name = 'last name'; $api_key = 'xx-us18'; // YOUR API KEY // server name followed by a dot.
<?php
error_reporting(-1);
ini_set('display_errors', 1);
$email = 'test@domain.com';
$first_name = 'name';
$last_name = 'last name';
$api_key = 'xx-us18'; // YOUR API KEY
// server name followed by a dot.
// We use us13 because us13 is present in API KEY
$server = 'us18.';
$list_id = 'xx'; // YOUR LIST ID
$auth = base64_encode( 'user:'.$api_key );
$data = array(
'apikey' => $api_key,
'email_address' => $email,
'status' => 'subscribed',
'merge_fields' => array(
'FNAME' => $first_name,
'LNAME' => $last_name
)
);
$json_data = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://'.$server.'api.mailchimp.com/3.0/lists/'.$list_id.'/members');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
'Authorization: Basic '.$auth));
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
$result = curl_exec($ch);
echo $result;
?>
有人知道我做错了什么吗?这个错误的原因可能是什么
额外信息:API密钥是有效的,如果我提供的是错误的,我将得到另一个错误。
列表id也是true。
我正在使用MAMP在本地主机上运行此代码。问题是我使用了web\u id而不是list\u id。
当我更改此选项时,问题已得到解决。如果您访问
http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/
在浏览器中,它会准确地告诉你为什么这不起作用——出于同样的原因,我已经有一段时间把头撞在墙上了。
{
type: "http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/",
title: "Resource Not Found",
status: 404,
detail: "The requested resource could not be found.",
instance: "78a35efa-ef43-471d-9e70-aecdc992d2e6"
}