karlicoss/HPI

Google Location data accessible through kml request

nathanmp opened this issue · 3 comments

Hi! I'm working on setting this up for my purposes and reading over the code. I wanted to let you know that I was looking on this site to see if there was a link to an API: https://www.google.com/maps/timeline?t=0&authuser=0&pb=!1m2!1m1!1s2020-09-18
When I clicked on the gear icon near the bottom, a new window pops up and downloads the location data for the day. That url is this: https://www.google.com/maps/timeline/kml?authuser=0&pb=!1m8!1m3!**1i2020!2i8!3i18**!2m3!1i2020!2i8!3i18

I'm not sure what all those numbers mean, but I was able to make sense of a few of them! I bolded the "meaningful" numbers above - they seem to be the ones starting after the 3rd exclamation point and ending right before the 6th. The first is the year, the second is the month (offset by one), and the last is the day. The following numbers were probably supposed to be an "end date" judging by the content of the file, but it seems it only returns the data of one day.

For instance, the file https://www.google.com/maps/timeline/kml?authuser=0&pb=!1m8!1m3!1i2018!2i1!3i1!2m3!1i2020!2i8!3i18 shows "Location history from 2018-02-01 to 2020-09-18", but the data ends at the start of 2018-02-02. Still, I was able to get data back from my account.

So this definitely could get data from the account. I also downloaded my cookies from that page and tested them using wget, and the file saved with no issues - they must not be checking user-agent (luckily). Anyway, I wanted to make you aware of this. I've cloned this and I'm currently writing a module to make that work - I could submit a pull request when I'm done if you want.

Hi! Thanks for the info!

Yep, I'd expect that google timeline has some sort of internal API, you can probably check with the browser Inspector for the responses. The only problem I see is that logging in with Google would usually require two factor auth -- so somewhat tedious to automate. Good to know that cookies work, although my gut feeling is that they will expire quickly, but let me know if I'm wrong!

By the way, quick search on github gives some results, which look promising, for example: https://github.com/bitsteller/LocationHistory Maybe someone has already deciphered the fields :)

Either way, if you implement a module, happy to accept a pull request!

I didn't need to use 2FA when I used wget, although it's enabled in my account. Also, by commenting cookies out of the file, I was able to narrow down the cookies that are required to download the data to three: SID, HSID, and SSID. SSID and HSID expire on 09/13/2022, and SID expires on 09/18/2022.

The only problem I can think of is that logging out and then logging in to a Google account would likely change those cookies - there'd need to be some sort of way to remind the user to refresh the cookie file and/or a method of automatically refreshing the cookie file.

Also I'm closing this, I meant for this to be a "heads up", not a "real" issue.