Click These:

Monday, December 15, 2025

How to set up OAUTH 2 via Google Cloud Console to use with a local python script



If you’re looking to set up OAuth 2.0 on Google Cloud to use with a local Python script, there are a few things you need to do. This was tricky for me initially, so for anyone who might be struggling to figure it out, here’s a quick guide to get you started.


1. Go to the Google Cloud Console and create a new project.


2. Give your project a name and click “Create”.


3. Once your project has been created, click on the “APIs & auth” menu item in the left hand sidebar.


4. In the APIs & auth menu, click on the “Credentials” sub-menu item.


5. On the Credentials page, click on the “Create new Client ID” button.


6. In the “Create Client ID” modal window, select the “Installed application” radio button and click “Configure consent screen”.


7. On the “Configure consent screen” page, fill in the “Product name” field and click “Save”.


8. Back in the “Create Client ID” modal window, select the “Other” radio button for the “Application type” field and click “Create Client ID”.


9. On the “Client ID created” page, copy down the “Client ID” and “Client secret” values. You will need these later.


10. Click on the “Download JSON” button and save the file to your computer.


11. Open the JSON file in a text editor and copy the contents into a new file called client_secrets.json in the same directory as your Python script.


12. Install the Google API Python client library by running the following command in a terminal:


pip install --upgrade google-api-python-client


13. Add the following lines of code to your Python script:
(in this example we're connecting to the calendar API)


from oauth2client.client import OAuth2WebServerFlow


flow = OAuth2WebServerFlow(client_id='YOUR_CLIENT_ID',

                           client_secret='YOUR_CLIENT_SECRET',

                           scope='https://www.googleapis.com/auth/calendar')


14. Replace YOUR_CLIENT_ID and YOUR_CLIENT_SECRET with the “Client ID” and “Client secret” values that you copied down earlier.


15. Run your Python script and follow the instructions that appear in the terminal to complete the OAuth 2.0 flow.


And that's it! Congrats, you should now have a working python script that can connect with Oauth 2!

I know it was pretty dry reading but if you liked this article feel free to share, subscribe, all that typical stuff... If you have any questions, I encourage you to ask in the comments.