簡體   English   中英

Firebase錯誤的雲函數:getaddrinfo ENOTFOUND

[英]Cloud Functions for Firebase Error: getaddrinfo ENOTFOUND

我有請求功能,並嘗試為Firebase集成寬度Cloud Functions。

var http = require("https");

    function addUserToMailchimpList(email) {
    var options = { method: 'POST',
      url: 'https://usxx.api.mailchimp.com/3.0/lists/xxxxxxx/members/',
      headers: 
       { 'content-type': 'application/json',
         'user' : 'anystring:xxxxxxxxxxxxxxxxxxxxxxx'
       },

      body: 
       { email_address: email,
         status: 'subscribed',
       },
      json: true };

    request(options, function (error, response, body) {
      if (error) throw new Error(error);
      console.log(body);
      console.log(error);
      console.loh(response);
    });

}

然后我正在嘗試部署此功能的寬度

exports.sendWelcomeEmail = functions.auth.user().onCreate(event => {
  const user = event.data; // The Firebase user.
  const email = user.email; // The email of the user.
  const displayName = user.displayName; // The display name of the user.

  return addUserToMailchimpList(email);
});

但是在firebase函數日志中,我得到了錯誤:

Error: Error: getaddrinfo ENOTFOUND usxx.api.mailchimp.com usxx.api.mailchimp.com:443

我做錯了什么? 不明白。

我正在嘗試使用的其他方法但存在相同的錯誤

function addUserToMailchimpList(email) {

  var options = {
    "method": "POST",
    "hostname": "usxx.api.mailchimp.com",
    "port": null,
    "path": "/3.0/lists/xxxxx/members/",
    "headers": {
      "content-type": "application/json",
      "user": "anystring:xxxxxxxxxx",
    }
  };

  var req = http.request(options, function (res) {
    var chunks = [];

    res.on("data", function (chunk) {
      chunks.push(chunk);
    });

    res.on("end", function () {
      var body = Buffer.concat(chunks);
      console.log(body.toString());
    });
  });

  req.write(JSON.stringify({ email_address: email,
    status: 'subscribed',
    merge_fields: { FNAME: 'xxx', LNAME: 'xxx' } }));
  req.end();

}

該博客文章建議您在從Firebase Cloud Function執行API請求之前,需要先啟用計費功能。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM