【问题标题】:How to validate Mailchimp API key in PHP?如何在 PHP 中验证 Mailchimp API 密钥?
【发布时间】:2016-04-12 03:16:05
【问题描述】:

如何验证 Mailchimp API 密钥是否有效或存在于 Mailchimp 中。我想将此密钥保存在数据库中,在此之前我需要验证给定的密钥。我看到这个Question 并关注它,但它对我不起作用。它什么也没显示。

这是我的代码:

validateApiKey('xxxxxxxxxxxxxxxxxxxxxxxxxx-us1');

function validateApiKey($api_key)
{
$data = array(
    'apikey' => $api_key,
    'cid' => "CID",
);
$data = json_encode($data);


$submit_url = "https://us10.api.mailchimp.com/2.0/reports/opened.json";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $submit_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_setopt($ch, CURLOPT_USERAGENT, 'MailChimp-PHP/2.0.6');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 600);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);

$result = curl_exec($ch);
curl_close ($ch);

$info = json_decode(json_encode(json_decode($result)), true);
print_r($info);
echo '<pre>';
var_dump($info);
echo '</pre>';

}

如何知道密钥是否有效。有什么建议吗?

【问题讨论】:

    标签: php validation mailchimp


    【解决方案1】:

    提出请求。如果请求有效,则密钥有效。在 v2.0 中,您可以使用 /2.0/helper/ping 端点。在 3.0 中,根 (/3.0/) 类似。

    【讨论】:

    • 我会把这个“/2.0/helper/ping”放在哪里?我该怎么做?谢谢
    • 这里是那个电话的docs。您可以像在示例代码中使用 reports/opened 一样使用它。
    猜你喜欢
    • 2018-07-01
    • 2016-01-29
    • 2015-03-08
    • 1970-01-01
    • 1970-01-01
    • 2022-08-03
    • 2022-10-05
    • 2019-02-26
    • 2020-12-02
    相关资源
    最近更新 更多