Google Home mini不要求DEVICE_COARSE_LOCATION

时间:2018-06-29 10:47:34

标签: actions-on-google

我正在构建一项服务,该服务需要设备存放所在的城市,一旦获得城市,便将其存储在用户存储中。 因此,在调用该函数时,它将首先检查userStorage中是否存在城市,如果不存在,则返回以询问DEVICE_COARSE_LOCATION

该服务在Google模拟器上的“操作”中运行正常,但是当我在Google Home mini上尝试使用它时,以下是我得到的错误

Error: Permission not granted
at app.intent (/user_code/index.js:76:11)
at Function.<anonymous> (/user_code/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:115:23)
at next (native)
at /user_code/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:22:71
at __awaiter (/user_code/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:18:12)
at Function.handler (/user_code/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:58:16)
at Object.<anonymous> (/user_code/node_modules/actions-on-google/dist/assistant.js:53:32)
at next (native)
at /user_code/node_modules/actions-on-google/dist/assistant.js:22:71
at __awaiter (/user_code/node_modules/actions-on-google/dist/assistant.js:18:12)

下面是我的代码

app.intent('LaundryIntent', (conv, {room}) => { 
      conv.data.requestedPermission = 'DEVICE_COARSE_LOCATION';
      if (!conv.user.storage.city) {
            return conv.ask(new Permission({
                context: 'To serve you better',
                permissions: conv.data.requestedPermission,
            }));
       }
       else
       {
            var city = conv.user.storage.city;
            do something then 
        }   
 });

这是处理许可的意图

   app.intent('actions_intent_PERMISSION', (conv, params, permissionGranted) => {
      if (!permissionGranted) 
      {
          throw new Error('Permission not granted');
      }
      const {requestedPermission} = conv.data;
      if (requestedPermission === 'DEVICE_COARSE_LOCATION') 
      {
         conv.user.storage.city = conv.device.location.city;
     }
  });

1 个答案:

答案 0 :(得分:1)

对于Google Home设备,您需要使用DEVICE_COARSE_LOCATION

签出Name Psychic sample code以获得权限

// If the request comes from a phone, we can't use coarse location.
conv.data.requestedPermission =
  conv.surface.capabilities.has('actions.capability.SCREEN_OUTPUT')
  ? 'DEVICE_PRECISE_LOCATION'
  : 'DEVICE_COARSE_LOCATION';
if (!conv.user.storage.location) {
  return conv.ask(new Permission({
    context: responses.permissionReason,
    permissions: conv.data.requestedPermission,
  }));
}
if (requestedPermission === 'DEVICE_COARSE_LOCATION') {
  // If we requested coarse location, it means that we're on a speaker device.
  conv.user.storage.location = conv.device.location.city;
  return showLocationOnScreen(conv);
}
if (requestedPermission === 'DEVICE_PRECISE_LOCATION') {
  // If we requested precise location, it means that we're on a phone.
  // Because we will get only latitude and longitude, we need to
  // reverse geocode to get the city.