【问题标题】:Recieving 401 error on mailchimp api fetch在获取 mailchimp api 时收到 401 错误
【发布时间】:2020-09-03 16:35:18
【问题描述】:
function emailSubscribe() {
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/)
     {
        const data = {
            members: [
              {
                email_address: document.getElementsByClassName("email input"),
                status: 'subscribed'
              }
            ]
          };

          const postData = JSON.stringify(data);

          fetch('https://us19.api.mailchimp.com/3.0/lists/mylist', {
            method: 'POST',
            mode: 'no-cors',
            headers: {
              Authorization: 'auth apikey-us19',
            },
            body: postData
          })
            .then(function(response) {
            response.statusCode === 200 ?
            alert("You have been successfully subscribed to StreamIntra. An email should be arriving shortly.") :
            alert("An error has occurred, please try again later.")
            .catch(console.log(response))
            })
           } else {
       alert("You have entered an invalid email address!")
     }
  }

我有这个函数,我通过本地快递服务器上的提交按钮调用它,但它一直给我一个 401 错误(不正确的 api 密钥)。我已经阅读了 api 并检查了我的 api 密钥,一切看起来都很好。我也尝试过编码和发送密钥,仍然没有。 我看过这个链接:MailChimp. Error 401 (Unauthorized) when sending a request for adding a new list member 但似乎没有提供答案。他提到 mailchimp 不适用于 cors,但我在 no-cors 模式下运行。有什么方法可以验证我的请求,以免我收到错误消息?

【问题讨论】:

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


    【解决方案1】:

    mailchimp 服务器有问题!尝试改用 firebase。

    尝试使用它。 :

    function emailSubscribe() {
        if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/)
         {
            const data = {
                email: document.getElementsByClassName("email input"),
                [ANY OTHER DATA YOU WANT]...
              };
    
              const postData = JSON.stringify(data);
    
              fetch('https://[YOUR ADDRESS].firebaseio.com/', {
                method: 'POST',
                mode: 'no-cors',
                headers: {
                  Authorization: '[APIKEY]',
                },
                body: postData
              })
                .then(function(response) {
                response.statusCode === 200 ?
                alert("You have been successfully subscribed to StreamIntra. An email should be arriving shortly.") :
                alert("An error has occurred, please try again later.")
                .catch(console.log(response))
                })
               } else {
           alert("You have entered an invalid email address!")
         }
      }
    

    【讨论】:

    • 嘿,你说得对,我确实认为这是 mailchimp 服务器的错误,但是我决定完全采用不同的方法来解决这个问题。
    猜你喜欢
    • 2019-07-30
    • 1970-01-01
    • 2022-06-21
    • 1970-01-01
    • 2014-06-11
    • 2020-07-04
    • 1970-01-01
    • 2021-08-04
    • 2018-05-14
    相关资源
    最近更新 更多