This script (python 3) generates tokens that can be used when making requests to the Google Home Foyer API. There are 2 kinds of tokens used here:
- Master token - Is in the form
aas_et/***
and is long lived. Needs Google username and password. - Access token - Is in the form
ya29.***
and lasts for an hour. Needs Master token to generate.
If you do not want to store the Google account password in plaintext, get the master token once, and set it as an override value.
It's safer/easier to generate an app password and use it instead of the actual password. It still has the same access as the regular password, but still better than using the real password while scripting. (https://myaccount.google.com/apppasswords)
# Install python requirements
pip install gpsoauth
# Update the constants at the beginning of the file
# Get the tokens!
python3 get_tokens.py
Hi
I am getting a weird error running this - whilst trying to resolve goog-home integration with homeassistant.
Ubuntu 22.04 and python 3.11. Latest available @ 2023-Mar-06
Traceback (most recent call last):
File "/home/homeassistant/get_tokens.py", line 70, in
device_id = _get_android_id()
^^^^^^^^^^^^^^^^^
File "/home/homeassistant/get_tokens.py", line 49, in _get_android_id
raise OSError("a valid MAC could not be determined."
OSError: a valid MAC could not be determined. Provide an android_id (and be sure to provide the same one on future runs).
I have used two different app passwords. One where I select Device Other first (and then no option to choose app is available), or app as Other (and then no optiion to choose device).
Versions are :
glocaltokens==0.7.0
gpsoauth==1.0.2
requests==2.28.2
requests-toolbelt==0.10.1
urllib3==1.26.14
If I try a random device_id, I cannot authenticate. Results below.
[] Getting master token...
[!] Could not get master token.
[] Master token: None
[] Getting access token...
[!] Could not get access token.
[] Access token: None
thanks
gb