0

Dialogflow의 Fullfilment 논리를 사용하여 Google 계정 정보를 얻고 싶습니다. 그러나 다음 오류가 발생합니다.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 

그러나 위 URL을 이행 할 때 위의 오류가 발생합니다. 아래 정의에 실수가 있습니까?

* Fullfilment를 사용하면 논리가 index.js에 설명되어 있습니다.

* 내가 코딩 실수를 발견

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

Firebase 기능을 사용하여 이것을 실행하고 있습니까? 그렇다면 Firebase 기능 콘솔의 로그를 포함 할 수 있습니까? – Prisoner

+0

'res.on ('error', err => {...})'핸들러를 추가하고 그 에러 로그를 볼 수 있습니까? – Prisoner

+0

클라우드 기능에서 OAuth 스타일 인증을 수행 할 수 있다고 생각하지 않습니다. 실행중인 코드는 최종 사용자의 데스크톱에서 실행될 것으로 예상되며, 브라우저에 로그인하여 로그인하여 앱에 정보에 대한 액세스 권한을 부여하도록 요청합니다. "127.0.0.1"오류 부분은 코드가 localhost의 브라우저와 통신하려고 시도하고 있음을 나타냅니다. –

답변

0

'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을하는 index.js.

오타 :

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

올바른 :

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

위를 시도하십시오. 감사합니다. .

+0

감사합니다. 도와 주셔서 대단히 감사합니다! – Masa

관련 문제