【问题标题】:MailChimp Error Status: 401 Title: "API Key Invalid"MailChimp 错误状态:401 标题:“API 密钥无效”
【发布时间】:2020-07-04 01:48:03
【问题描述】:

我正在关注MailChimp API tutorial

当我测试 API 时,我收到 401 响应,说我的 API 密钥无效。

错误 - 状态:401

“您的 API 密钥可能无效,或者您尝试访问错误的数据中心。”

我还没有注册域,正在使用本地服务器进行测试。这可能是由于 MailChimp 出于其他原因(可能是 CORS)拒绝请求而导致的错误吗?

app.post('/signup', (req, res) => {
  // Get form data
  const { email } = req.body;

  // Make sure field is filled
  if(!email) {
    res.redirect('/html/fail.html');
    return;
  }

  // Construct req data
  const data = {
    members: [
      {
        email_address: email,
        status: 'subscribed'
      }
    ]
  }
  // Convert to JSON
  const postData = JSON.stringify(data);

  const options = {
    url: 'https://us19.api.mailchimp.com/3.0/lists/listID',
    method: 'POST',
    headers: {
      Authorization: 'auth xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-us19'
    },
    body: postData
  };

  request(options, (err, response, body) => {
    if(err) {
      console.log(err);
      res.redirect('/html/fail.html');
    } else {
      if(response.statusCode === 200) {
        res.redirect('/html/success.html');
      } else {
        console.log(response.body);
        res.redirect('/html/fail.html');
      }
    }
  });
})

【问题讨论】:

  • 先检查您的 API 密钥,我看到其他人在没有请求的情况下将其删除。

标签: javascript node.js express mailchimp-api-v3.0


【解决方案1】:

我尝试在 PostMan 的 request 中运行相同的代码,但得到了 200 响应。

我最初是从配置文件中导入 API 密钥,但我没有解构...

【讨论】:

    猜你喜欢
    • 2022-09-30
    • 2015-03-08
    • 2019-02-26
    • 1970-01-01
    • 2020-01-31
    • 2017-09-05
    • 1970-01-01
    • 1970-01-01
    • 2020-10-13
    相关资源
    最近更新 更多