Google Home mini 不要求 DEVICE_COARSE_LOCATION

Google Home mini not asking for DEVICE_COARSE_LOCATION

我正在构建一项服务,该服务需要保存设备的城市,一旦获得城市,我就会将其存储在用户存储中。 因此,当调用该函数时,它首先检查该城市是否存在于 userStorage 中,如果不存在,则它 return 请求 DEVICE_COARSE_LOCATION

该服务在 google 模拟器上的 Actions 中工作得很好,但是当我在 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;
     }
  });

对于 Google 家用设备,您需要使用 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.