Node.js 如何从api获取数据并使用实现在操作中显示?
如何从api()获取数据并使用实现在操作中显示 我的代码:Node.js 如何从api获取数据并使用实现在操作中显示?,node.js,actions-on-google,dialogflow-es,fulfillment,Node.js,Actions On Google,Dialogflow Es,Fulfillment,如何从api()获取数据并使用实现在操作中显示 我的代码: function apiCall(agent){ https.get('https://jsonplaceholder.typicode.com/posts/1', (resp) => { let data = ''; // A chunk of data has been recieved. resp.on('data', (chunk) => { d
function apiCall(agent){
https.get('https://jsonplaceholder.typicode.com/posts/1', (resp) => {
let data = '';
// A chunk of data has been recieved.
resp.on('data', (chunk) => {
data += chunk;
});
// The whole response has been received. Print out the result.
resp.on('end', () => {
console.log(JSON.parse(data).explanation);
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
}
我得到一个错误:
函数中:getaddrinfo ENOTFOUND jsonplaceholder.typicode.com jsonplaceholder.typicode.com:443
我已经测试了API服务器,它工作得很好
原因
我在尝试从云函数访问API服务器时遇到了同样的问题。那一次的计费并不是解决方案,因为我已经启用了计费功能
解决方案
实现webhook url
中,这是一个很好的开发解决方案我已经测试了API服务器,它工作得很好
原因
我在尝试从云函数访问API服务器时遇到了同样的问题。那一次的计费并不是解决方案,因为我已经启用了计费功能
解决方案
实现webhook url
中,这是一个很好的开发解决方案您希望在此页面中收到什么? 我复制了你的代码并更改了
console.log(JSON.parse(data).explanation);
到
它还给我这个:
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}
这就是为什么当我点击你的链接时我会得到
我对您的代码没有任何错误,只是“解释”字段对我来说不存在
由于我不明白消息的意思,您的站点是否需要一些身份验证或其他信息?您希望在该页面中收到什么? 我复制了你的代码并更改了
console.log(JSON.parse(data).explanation);
到
它还给我这个:
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}
这就是为什么当我点击你的链接时我会得到
我对您的代码没有任何错误,只是“解释”字段对我来说不存在
由于我不明白消息的意思,您的站点是否需要一些身份验证或其他什么?Google GitHub上的Actions上有一个托管的示例,演示了如何从实现Webhook进行外部API调用
如示例自述中所述,如果您正在使用Firebase的云功能部署您的履行,您需要升级您的计划,由于Firebase的免费层不支持进行出站网络调用。Google GitHub上的操作中有一个托管的应用程序,演示了如何从实现Webhook进行外部API调用
如示例自述中所述,如果您使用Firebase的云功能部署您的履行,则需要升级您的计划,因为Firebase的免费层不支持进行出站网络呼叫