Get your Google Location History the hard way… Again!


Last year, I wrote about how to extract Location History from Google. Once again, Google have changed their URLs to make it even harder to get one's current location out of their data-greedy hands.

It used to be the case that Latitude gave that information - but they killed it. Then they promised it in Google+ - but never delivered. Now they offer you a data-dump which they will email to you. Hardly convenient if you want a single day!

*sigh*

Recently Google released Timeline - an interactive way to view where you've been. It also offers the ability to download a single day's worth of location tracks as KML.

Google Timeline KML-fs8

With a little bit of fiddling, we can get the direct URL. Strap in, it's going to get rough!

In order to get today's date (2015-09-02) the URL needs to be:

https://www.google.com/maps/timeline/kml?authuser=0&pb=!1m8!1m3!1i2015!2i8!3i2!2m3!1i2015!2i8!3i2

That URL format is… unique…

Here's how it breaks down:

pb=!1m8!1m3!1iYYYY!2iMM!3iDD!2m3!1iYYYY!2iMM!3iDD

Where MM is a Javascript style zero-based month. (Why is the first month "0" but the first day "1"? Because fuck you, that's why!)

One thing to note, when you get the KML file, the timestamps are in ISO 8601 format (Yay!) but are set to West Coast USA time (Boo!)
2015-09-02T12:15:37.836-07:00

Annoying, but not the end of the world. How do you get the data into your app?

You can't.

There's no authorised API access for this. You can't do the OAuth dance. The only way is via cookie-jacking.

Sign in to Google via your web browser. Open up your web inspector in Chrome or Firefox. Load the KML URL and choose "Copy as cURL"
Cookie Jacking-fs8

You'll end up with a command like:

curl 'https://www.google.com/maps/timeline/kml?authuser=0&pb=!1m8!1m3!1i2015!2i8!3i2!2m3!1i2015!2i8!3i2'
 -H 'Host: www.google.com'
 -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:40.0) Gecko/20100101 Firefox/40.0'
 -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
 -H 'Accept-Language: en-GB,en;q=0.5'
 --compressed
 -H 'DNT: 1'
 -H 'Cookie: --------------'
 -H 'Connection: keep-alive'

You can use that command - or steal your own cookie - for use in your app. Your cookie will likely expire after a set time - whereupon you'll have to reauthenticate.

What a faff! Come on, Google. Rather than pissing about with your logo, why not build something that works properly? I dare ya!

7 thoughts on “Get your Google Location History the hard way… Again!

  1. Thanks for the post! This has greatly helped me in my application. However, I'm wondering if there's a way to do this without having to explicitly extracting your own cookie. If a user is signed into Google already, shouldn't there be a way to grab the data within a javascript script?

  2. I got a Syntax error when trying the above. My copied cURL format from the inspector looks like this:

    curl "https://www.google.nl/maps/timeline/kml?authuser=1&pb=!1m8!1m3!1i2017!2i4!3i3!2m3!1i2017!2i4!3i3"
    --2.0
    -H "Host: http://www.google.nl"
    -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0"
    -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8"
    -H "Accept-Language: en-US,en;q=0.5"
    --compressed
    -H "Cookie: NID=102= long string of code here;
    CONSENT=YES+NL.nl+V8;
    SID= some code here;
    HSID= code here; SSID= code here;
    APISID= code here;
    SAPISID=code here;
    OGPC= code here;
    OGP= code here;
    DV= code here"
    -H "Connection: keep-alive"
    -H "Upgrade-Insecure-Requests: 1

    How can I adapt it to make it work?

Leave a Reply

Your email address will not be published. Required fields are marked *