尝试使用以下代码访问基于位置的服务。未授予技能许可。我已为所有 Alexa 应用程序启用位置服务。我还在开发者门户中启用了此功能。我的手机打开了定位服务。我在这里可能缺少什么?
if (isGeoSupported) { // does the device support location based features? {
var geoObject = context.Geolocation;
if ( ! geoObject || ! geoObject.coordinate){
var skillPermissionGranted = context.System.user.permissions.scopes['alexa::devices:all:geolocation:read'].status === "GRANTED";
if ( ! skillPermissionGranted) {
// location not authorized
return handlerInput.responseBuilder
.speak('Permission is not granted to access location')
.getResponse();
}
您的技能需要请求许可才能使用用户位置。一旦获得许可,只要设备支持定位服务(运行 Alexa 应用程序的手机即可)并且用户还必须拥有定位服务,您的技能从该用户收到的每个请求都会发送纬度/经度信息为 Alexa 应用程序启用。
因此,这并非没有摩擦,但满足所有这些条件后,位置就会开始出现在请求中。要进行检查,只需将请求记录到 CloudWatch,您就会在请求 JSON 中找到它。