0
我有請求函數,並嘗試整合Firebase的寬度雲端函數。Firebase錯誤的雲端函數:getaddrinfo ENOTFOUND
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);
});
}
然後我tryng部署寬度此功能
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);
});
但在火力功能的日誌我得到錯誤:
Error: Error: getaddrinfo ENOTFOUND usxx.api.mailchimp.com usxx.api.mailchimp.com:443
什麼,我做錯了什麼?不是undestand ..?
其它方法,我tryng使用,但同樣的錯誤
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();
}
「usxx.api.mailchimp.com」無法解析爲IP號碼。無論是主機名無效,您的DNS不知道它,一些防病毒軟件/防火牆軟件阻止查找,等等。 – robertklep
我是從本地主機deployng,但功能從firebase執行 –
也許你不允許創建來自Firebase的網絡連接? [此博客](https://www.automationfuel.com/firebase-functions-sending-emails/)表明,爲了發出外部API請求,您需要啓用結算。 – robertklep