I want to save my google location history in a regular basis.
Usually I use the Webinterface: https://maps.google.com/locationhistory/b/0
it also provides a lin
Replying late on this, but may be this will also help someone else:
Another easy way to export cookie is to first login on chrome using google username and password then use this extension export cookie to export cookie into a file. After that you can use this file with wget to download document with --load-cookies options like:
wget --user-agent="Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:25.0) Gecko/20100101 Firefox/25.0 FirePHP/0.7.4" --load-cookies cookie.txt -p --keep-session-cookies "http://google.com/"
You get a 302 Moved Temporarily
because you need to be authenticated: Google is redirecting you to its login page.
Once authenticated, google credentials are stored in browser cookies. If you want to download the Google maps location history link, then you have to provide browser cookies with curl
. The -b
option of curl
allows you to use a cookies.txt
with respect to Netscape/Mozilla cookie file format.
Each line of the
cookies.txt
has seven tab-separated fields:
- domain - The domain that created AND that can read the variable.
- flag - A TRUE/FALSE value indicating if all machines within a given domain can access the variable. This value is set automatically by the browser, depending on the value you set for domain.
- path - The path within the domain that the variable is valid for.
- secure - A TRUE/FALSE value indicating if a secure connection with the domain is needed to * access the variable.
- expiration - The UNIX time that the variable will expire on. UNIX time is defined as the number of seconds since Jan 1, 1970 00:00:00 GMT.
- name - The name of the variable.
- value - The value of the variable.
So the simplest solution is to export your browser cookies to a cookies.txt
file and instruct curl
to use them. In Chrome, cookies are stored in a sqlite3 database. You can export them with the following command:
sqlite3 ~/.config/google-chrome/Default/Cookies \
'select host_key, "TRUE", path, "FALSE", expires_utc, name, value from cookies where host_key like "%google.com"' \
| tr '|' '\t' > /tmp/cookies.txt
Note the host_key like "%google.com"
which limits exported cookies.
Invoke curl
with -b /tmp/cookies.txt
to use the exported cookies and authenticate to googles maps and you will be able to download the google maps location history
curl -b /tmp/cookies.txt https://maps.google.com/locationhistory/b/0/kml\?startTime\=1376604000000\&endTime\=1376690400000
To avoid storing your cookies in a temporary file, use this command:
curl -b <(sqlite3 ~/.config/google-chrome/Default/Cookies 'select host_key, "TRUE", path, "FALSE", expires_utc, name, value from cookies' | tr '|' '\t') https://maps.google.com/locationhistory/b/0/kml\?startTime\=1376604000000\&endTime\=1376690400000