gpt4 book ai didi

node.js - Dialogflow的Fullfilment逻辑无法获取Google帐户信息

转载 作者:太空宇宙 更新时间:2023-11-04 01:56:30 24 4
gpt4 key购买 nike

我想使用 Dialogflow 的 Fullfilment 逻辑获取 Google 帐户信息,但出现以下错误。

Error: connect ECONNREFUSED 127.0.0.1:443 at 
Object.exports._errnoException (util.js:1020:11) at
exports._exceptionWithHostPort (util.js:1043:20) at
TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)

帐户关联已设置,并在客户端通过 Google 帐户进行认证。我可以通过在浏览器中执行以下URL来获取用户信息。

https://www.googleapis.com/oauth2/v1/userinfo?access_token=foo_bar

但是,如果我在 Fulfillment 上访问上述 URL,则会出现上述错误。下面的定义有错误吗?

*使用Fullfilment,逻辑在index.js中描述。

*index.js

'use strict';

const App = require('actions-on-google').DialogflowApp;

exports.testFunc = (req, res) => {

const app = new App({request:req, response:res});
let accessToken = app.getUser().accessToken;
console.log('accessToken is ' + accessToken);

getUserInfo(accessToken).then((output) => {
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify({ 'speech': output, 'displayText': output }));
}).catch((error) => {
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify({ 'speech': error, 'displayText': error }));
});
};
function getUserInfo (accessToken) {
return new Promise((resolve, reject) => {

let https = require('https');
let host = 'www.googleapis.com';
let path = '/oauth2/v1/userinfo?access_token=' + accessToken;
console.log('API Request: ' + host + path);

https.get({hostName: host, path: path}, (res) => {
let body = ''; // var to store the response chunks
res.on('data', (d) => {
body += d;
console.log('data: ' + body);
}); // store each response chunk
res.on('end', () => {
console.log('end');
let output = `response`;
console.log(output);
resolve(output);
});
res.on('error', (error) => {
reject(error);
});
});
});
}

*package.json

{
"name": "testFunc",
"engines": {
"node": "~4.2"
},
"dependencies": {
"actions-on-google": "^1.0.0",
"firebase-admin": "^4.2.1",
"firebase-functions": "^0.5.7"
}
}

最佳答案

我发现你的编码错误。

拼写错误:

https.get({hostName: host, path: path}, (res) => {

正确:

https.get({host: host, path: path}, (res) => {

请尝试以上操作。谢谢。

关于node.js - Dialogflow的Fullfilment逻辑无法获取Google帐户信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47754305/

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