简体   繁体   English

Firebase错误的云函数:getaddrinfo ENOTFOUND

[英]Cloud Functions for Firebase Error: getaddrinfo ENOTFOUND

I have request function and tryng to integrate width Cloud Functions for Firebase. 我有请求功能,并尝试为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);
    });

}

Then I am tryng to deploy width this function 然后我正在尝试部署此功能的宽度

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);
});

but in firebase functions log I am getting error: 但是在firebase函数日志中,我得到了错误:

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

what I am doing wrong? 我做错了什么? not undestand.. ? 不明白。

other method I am tryng to use but same error 我正在尝试使用的其他方法但存在相同的错误

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