Mailchimp v3 api返回错误

时间:2018-05-15 18:08:28

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

我写了curl请求来获取自动化链接。但它返回401。 我只需通过GET调用自动列表。 我不清楚我的代码是什么问题。我相信卷毛是好的。 有什么想法吗?

// Here is the data we will be sending to the service
  $some_data = array(
    'apikey' => 'xxxxxxxxwqew3423xxxxx'
  );  

  $curl = curl_init();
  // You can also set the URL you want to communicate with by doing this:
  // $curl = curl_init('http://localhost/echoservice');

  // We POST the data
  curl_setopt($curl, CURLOPT_POST, 1);
  // Set the url path we want to call
  curl_setopt($curl, CURLOPT_URL, 'https://us13.api.mailchimp.com/3.0/automations');  
  // Make it so the data coming back is put into a string
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  // Insert the data
  curl_setopt($curl, CURLOPT_POSTFIELDS, $some_data);

  // You can also bunch the above commands into an array if you choose using: curl_setopt_array

  // Send the request
  $result = curl_exec($curl);

  // Get some cURL session information back
  $info = curl_getinfo($curl);  

  print_r($info);
  echo 'content type: ' . $info['content_type'] . '<br />';
  echo 'http code: ' . $info['http_code'] . '<br />';

  // Free up the resources $curl is using
  curl_close($curl);

  echo $result;

回应是:

http code: 401
{"type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/","title":"API Key Missing","status":401,"detail":"Your request did not include an API key.","instance":"xxxxx-xxxxxx-xxxxxxxx"}

1 个答案:

答案 0 :(得分:0)

解决了这个问题。

API密钥应包含服务器编号。例如,对我来说服务器是u13, 所以api是:dfsdfsdfsdffsdfsdf-u13

相关问题