【问题标题】:get data from mailchip using curl where do I place the api key in the curl call使用 curl 从 mailchimp 获取数据我在哪里将 api 密钥放在 curl 调用中
【发布时间】:2019-03-02 06:50:26
【问题描述】:

我正在尝试使用 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>';

【问题讨论】:

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


    【解决方案1】:

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

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

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

    【讨论】:

    • 非常感谢,我添加了代码但仍然没有成功...可能是什么问题?
    猜你喜欢
    • 1970-01-01
    • 2011-09-28
    • 1970-01-01
    • 2016-09-23
    • 2016-05-13
    • 2016-01-11
    • 2017-11-10
    • 1970-01-01
    • 2017-04-11
    相关资源
    最近更新 更多