我正在关注this tutorial以创建一个动作,该动作将请求访问用户位置的权限并回读其地址;但是,当智能助理完成时,我无法确认权限请求。
当我被问到是否可以从Google获取我的地址时,无论我给出的响应是什么,我都会给“助理”回复“抱歉,我没有抓到”或类似的东西。我很难过我做错了什么,而且我确信我已经按照教程来写了这封信。
我已经包含了我的意图,部署在Firebase云功能上的代码,以及我从智能助理中获得的输出。
// Dialogflow modified SillyNameMaker example
'use strict';
process.env.DEBUG = 'actions-on-google:*';
const App = require('actions-on-google').DialogflowApp;
const functions = require('firebase-functions');
exports.sillyNameMaker = functions.https.onRequest((request, response) => {
const requestPermission = (app) => {
app.askForPermission('To locate you', app.SupportedPermissions.DEVICE_PRECISE_LOCATION);
};
const userInfo = (app) => {
if (app.isPermissionGranted()) {
const address = app.getDeviceLocation().address;
app.tell(`You are at ${address}`);
} else {
app.tell('Sorry, I could not figure out where you are.');
}
};
const app = new App({ request, response });
const actions = new Map();
actions.set('request_permission', requestPermission);
actions.set('user_info', userInfo);
app.handleRequest(actions);
});
答案 0 :(得分:0)
你必须回答两次!
"要找到您,我只需要从Google获取您的街道地址。那可以吗?"
"是"
"抱歉,我没有得到。"
"我说是的。" /"是" /"当然!"等
现在可以使用启用权限执行意图的功能。
我认为这是某种安全检查。由于此设计,这意味着您在请求后依赖的任何lifespan
对象必须至少2
@ionic-native/core@4.4.2
才能与您联系。我将它们设置为一个非常高的值,然后在我的回调中手动删除它们,以防权限操作比这更长时间(即多次验证尝试失败)。