Google 是否公开“查找我的设备”API?

问题描述 投票:0回答:1

Google 拥有“查找我的设备”服务,可让您找到您的手机、使其响铃(即使处于静音状态)、远程擦除手机等,只需在此处输入:https://myaccount.google.com/find-your -电话

我想知道是否有一个 API 可以公开这些功能供其他人使用。

我对“响铃”功能特别感兴趣,我并不真正需要位置数据。

rest google-api google-contacts-api google-people-api
1个回答
0
投票

我能找到的最好的是这个 Chrome 扩展源代码

该扩展程序使用以下代码获取给定日期的时间线数据的 KML 导出(一次一个日期)(source):

for (let date = fromDate; date <= toDate; date.setDate(date.getDate() + 1)) {
  const year = date.getFullYear()
  const month = date.getMonth()
  const day = date.getDate()
  const uri = `https://www.google.com/maps/timeline/kml?authuser=0&pb=!1m8!1m3!1i${year}!2i${month}!3i${day}!2m3!1i${year}!2i${month}!3i${day}`
  requests.push(axios.get(uri))
}

您只需在当前日期提出以下请求之一。

接下来,扩展程序按如下方式解析响应,使用

mapbox
NPM 库(使用付费云服务)来解析 KML(XML)并迭代其中的“功能”。

const kml = new DOMParser().parseFromString(response.data, 'application/xml')
const gj = toGeoJSON.kml(kml)
gj.features.forEach(feature => {
  const timeBegin = moment(feature.properties.timespan.begin)
  const timeEnd = moment(feature.properties.timespan.end)
  const duration = moment.duration(timeEnd.diff(timeBegin)).asMilliseconds()
  data.items.push({
    name: feature.properties.name,
    address: feature.properties.address,
    timeBegin: feature.properties.timespan.begin,
    timeEnd: feature.properties.timespan.end,
    duration: duration,
    category: feature.properties.Category,
    distance: feature.properties.Distance,
    latitude: feature.geometry.type === 'Point' ? feature.geometry.coordinates[1] : null,
    longitude: feature.geometry.type === 'Point' ? feature.geometry.coordinates[0] : null
  })
})

我想数组中的最后一个

feature
将包含最近报告的位置,因此您应该能够直接跳到该位置。

如果时间还很早,并且用户的设备尚未报告位置,则如果对第一个请求的响应中没有任何功能,您将需要一个后备机制来请求前一天的位置。

您当然不需要付费库来解析 XML;有许多免费的 JS/TS XML 解析器库应该能够完成这项工作。从那里开始,只需理解响应的内容并提取您想要的数据即可。

综上所述:Chrome 扩展程序似乎在 CORS 方面拥有一些特殊权限(可能还有其他好处),当然它们还具有能够使用浏览器现有登录 Google 的好处(如果存在)。我自己尝试使用这种方法(在maps.google.com 时通过浏览器JS 控制台),但没有成功。但我只花了几分钟尝试;也许你会更幸运!

© www.soinside.com 2019 - 2024. All rights reserved.