使用curl从mailchip获取数据,我在curl调用中放置api密钥的位置

时间:2018-09-26 13:13:16

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

我正在尝试使用curl从mailchimp中获取列表成员。

这是我的代码。

我无法确定api密钥的放置位置。

这是我现在拥有的代码:

$apiKey = 'xxxxxxxxxxxxxxxxxx';
$list_id = 'aaaaaaaaaa';
$dataCenter = substr($apiKey,strpos($apiKey,'-')+1);

$url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/'.$list_id;

$cURL = curl_init();

curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_HTTPGET, true);

curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Accept: application/json'
));

$result = curl_exec($cURL);

curl_close($cURL);

echo '<pre>';

var_dump($result);

echo '</pre>';

1 个答案:

答案 0 :(得分:0)

据我所读的mailchimp documents,也许您需要添加CURLOPT_USERPWD选项。

curl_setopt($cURL, CURLOPT_USERPWD, $username . ':' . $apiKey);

请将您的mailchimp用户名设置为$username