我无法通过“ DialogflowApp.getUser”获取信息。方法 [英] I can not get information with "DialogflowApp.getUser" method
问题描述
https://developers.google.com/actions/reference/nodejs/ApiAiApp
我想通过参考上述官方网站在Dialogflow上获取访问令牌,但执行 DialogflowApp的结果.getUser()
将为空。
I'd like to obtain an access token on Dialogflow by referring to the above official website, but the execution result of DialogflowApp.getUser()
will be null.
已建立帐户链接,并在客户端通过了Google帐户认证。 DialogFlow Simulator的调试选项卡上的
AssistantToAgentDebug.assistantToAgentJson.user
包含一个值。
Account linking is set up and on the client side it is certified with a Google Account.
AssistantToAgentDebug.assistantToAgentJson.user
on the DEBUG tab of DialogFlow Simulator contains a value.
此外,我可以通过在请求正文上引用 req.body.originalRequest.data.user.accessToken
变量来获取访问令牌。
Also, I can get an access token by referring req.body.originalRequest.data.user.accessToken
variable on the request body.
我想使用 DialogflowApp.getUser()
,
获取用户信息以下定义中有错误吗?
I'd like to obtain user information with DialogflowApp.getUser()
,
Is there a mistake in the definition below?
*使用Fullfilment,其逻辑在index.js中进行了描述。
*Using the Fullfilment, the logic is described in index.js.
* index.js
*index.js
'use strict';
const App = require('actions-on-google').DialogflowApp;
exports.testMethod = (req, res) => {
// result is null
const app = new App({req, res});
let user = app.getUser();
console.log('User is ' + user);
// Access token can be acquired
let accessToken = req.body.originalRequest.data.user.accessToken;
console.log('accessToken is ' + accessToken);
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify({ 'speech': 'success!', 'displayText': 'success!' }));
};
* package.json
*package.json
{
"name": "testMethod",
"engines": {
"node": "~4.2"
},
"dependencies": {
"actions-on-google": "^1.0.0",
"firebase-admin": "^4.2.1",
"firebase-functions": "^0.5.7"
}
}
推荐答案
问题在于对构造函数的调用期望参数被命名为 request
和 response
。因此,您应该将该行写为
The problem is that the call to the constructor expect the parameters to be named request
and response
. So you should write the line as
const app = new App({request:req, response:res});
这篇关于我无法通过“ DialogflowApp.getUser”获取信息。方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!