This is a detailed version of the Alternative flow for gpsoauth I'm using uv for my python project but you can use whatever python package manager you like.
This python 3 script generates a Master token which can be used for a number of applications. I'm using mine for the Home Assistant custom integration.
I've created this gist because I was unable to get the following methods working with 2fa enabled on my google account:
Try these methods first, then the following as an alternative.
It's important to know the different types of tokens and when they expire:
- OAuth token - Is in the form oauth2_4/*** and is very short lived. Needs oauth sign form for an application.
- 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.
- Create a new project directory on your local machine and initialise a new python project.
uv init && uv venv && source .venv/bin/activatefor uv. - Add the dependency for gpsoauth.
uv add gpsoauthfor uv. - Copy the file
get_master_token.pyfrom this gist to your local machine and replace the email address with your email address. - Go to https://accounts.google.com/EmbeddedSetup
- Log into your Google Account and follow any additional login steps.
- Click on "I agree" when prompted. The page may show a loading screen forever; ignore it and move on to the next step.
- Obtain the value of the
oauth_tokencookie. Follow one of the two methods detailed in this readme if you are unsure how. - Replace the oauth token you receive from the step above in the token value in the
get_master_token.pyscript. - Run the
get_master_token.pyscript.uv run get_master_token.pyfor uv.
- Make sure you have replace the values for your email address and token in the script.
- The oauth token is only valid for a single use and expires quickly. Make sure you use it as soon as possible.