gpt4 book ai didi

javascript - Firebase 的云函数错误 : getaddrinfo ENOTFOUND

转载 作者:行者123 更新时间:2023-12-03 03:31:36 25 4
gpt4 key购买 nike

我有请求功能并尝试集成 Firebase 的宽度云功能。

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

}

最佳答案

This blogpost建议您先启用计费功能,然后才能从 Firebase 云功能执行 API 请求。

关于javascript - Firebase 的云函数错误 : getaddrinfo ENOTFOUND,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46071153/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com