在mailchimp api上接收401错误

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模式下运行。有什么方法可以验证我的请求,这样我就不会收到错误消息?

mars00721 回答:在mailchimp api上接收401错误

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!")
     }
  }
本文链接:https://www.f2er.com/2332199.html

大家都在问