MailChimp API v2:验证错误 [英] MailChimp API v2: Validation Error
问题描述
我在Mailchimp上遇到此问题,我的通话似乎被拒绝并失败. Mailchimp支持不知何故甚至看不到我尝试使用此代码对其进行呼叫
I have this problem with Mailchimp that my call seems to be denied and fail. Somehow Mailchimp Support can not even see that I tried to call them with this code
$data = array(
'apikey' => "APIKEY-USXX",
'cid' => "CID",
);
$data = json_encode($data);
echo '<pre>';
var_dump($data);
echo '</pre>';
$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, urlencode($data));
$result = curl_exec($ch);
curl_close ($ch);
$info = json_decode(json_encode(json_decode($result)), true);
echo '<pre>';
var_dump($info);
echo '</pre>';
奇怪的是,这对于我用API 1.3进行的任何其他调用都很好.我真的迷失了我在这里做错的事情.希望你们能帮助我吗?
The strange thing is, this works just fine for any other call i make with API 1.3. I'm really lost in what iam doing wrong here. Hope you guys can help me?
先谢谢了.
**编辑** 这是我的回复:
** EDIT ** Here is my response:
array(4) {
["status"]=>
string(5) "error"
["code"]=>
int(-100)
["name"]=>
string(15) "ValidationError"
["error"]=>
string(31) "You must specify a apikey value"
}
对我有用的最终代码:
$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);
推荐答案
确保提交URL(us10)中的"dc"与API密钥的最后一部分匹配.
Make sure the 'dc' in the submit URL (us10) matches the last portion of your API key.
也...尝试在通话中添加以下选项:
Also... try adding the following options to the call:
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);
您还可以添加以下选项以更明确地调试呼叫
You can also add the following option to debug the call more explicitly
curl_setopt($ch, CURLOPT_VERBOSE, true);
这篇关于MailChimp API v2:验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!