2017-12-18 64 views
0

我试图让火力地堡的用户ID来我的谷歌用户,但显然它是不确定的获取用户ID GoogleActions

dialogflowFirebaseFulfillment 
ReferenceError: userId is not defined 
    at IncomingMessage.resp.on (/user_code/index.js:73:17) 
    at emitNone (events.js:91:20) 
    at IncomingMessage.emit (events.js:185:7) 
    at endReadableNT (_stream_readable.js:974:12) 
    at _combinedTickCallback (internal/process/next_tick.js:80:11) 
    at process._tickDomainCallback (internal/process/next_tick.js:128:9) 

这是我的代码

const REQUEST_PERMISSION_ACTION = 'request_permission'; 
    const userUID = app.getUser().userId; 
    const userName = app.getUserName().displayName; 
    console.log(userUID, 'USERRRRRRID'); 

我能做些什么来获取用户标识?

+0

见https://stackoverflow.com/questions/47749476/i-can-not-get-information-with-dialogflowapp-getuser-method/47752302 – Bart

+0

我试图让我的令牌但显然它是空的(TypeError:无法读取null属性的'accessToken') –

+0

我指的是关于'const app = new App({request:req,response:res})的囚徒的帖子;'尝试添加更多的代码给您的帖子,以便我们可以帮助更好,如果这不起作用。 – Bart

回答

0

这是我的代码

function processV1Request (request, response) { 
    let action = request.body.result.action; // https://dialogflow.com/docs/actions-and-parameters 
    let parameters = request.body.result.parameters; // https://dialogflow.com/docs/actions-and-parameters 
    let inputContexts = request.body.result.contexts; // https://dialogflow.com/docs/contexts 
    let requestSource = (request.body.originalRequest) ? request.body.originalRequest.source : undefined; 
    const googleAssistantRequest = 'google'; // Constant to identify Google Assistant requests 
    const app = new DialogflowApp({request: request, response: response}); 
    // Create handlers for Dialogflow actions as well as a 'default' handler 
    const actionHandlers = { 
    // The default welcome intent has been matched, welcome the user (https://dialogflow.com/docs/events#default_welcome_intent) 
    'input.welcome':() => { 
    sendGoogleResponse(' Bonjour, Que puis je faire pour vous ?'); 
    }, 
    'input.what':() => { 

    const http = require('http'); 
    const https = require('https'); 
    https.get('https://bnpparibas-api.openbankproject.com/obp/v3.0.0/my/banks/bnpparibas.07.fr/accounts/cbf874f8-9eb1-4fdf-899c-54b8c5e7c2c8/account', (resp) => { 
    let data = ''; 
    const app = new ActionsSdkApp({request: request, response: response}); 



    // A chunk of data has been recieved. 
    resp.on('data', (chunk) => { 
    data += chunk; 

    }); 
+1

如果你在你的http调用之前放置'const userUID = app.getUser()。userId;'它应该工作吗? – Bart

+0

Ohhhh完美的作品<3感谢Bart! –

+1

仅供将来参考 - 您不应将后续信息作为答案,您可以编辑原始问题。 Bart应该将其作为答案发布,以便您可以接受答案,而其他人则可以对此作出回应。隐藏在评论中,其他人可能找不到它。 – Prisoner

0

你要问助手,引导用户授予权限为您的应用程序来获取此信息更大的作用。

看看here

+1

不,你不知道。这只有当你想要用户名或其他信息。 userId可以在任何时候获得,没有任何额外的权限。 – Bart

+0

对不起,你是对的,只有在获得其他信息时。 –