Search code examples
pythongoogle-apigmailgoogle-api-python-client

What should my URI be for Google Cloud API


I would like to send emails using the Gmail API from a python script I have on my computer.

Here is the code I have so far:

test.py

from google_auth_oauthlib.flow import InstalledAppFlow
flow = InstalledAppFlow.from_client_secrets_file('client_secret.json',scopes=['email'], redirect_uri='http://localhost/authorize/')
flow.run_local_server()

When I execute this, it redirects me to a separate url shows this

IMG

My understanding of this problem is that I need to have a redirect uri that matches one on my google cloud platform dashboard for this app. The only thing is I just want to run this locally so I placed the uri http://localhost/authorize instead.

To confirm, I did add http://localhost/authorize to my redirect uri on the Google Cloud Platform.

I referenced this answer I found but could not find my solution: Correct redirect URI for Google API and OAuth 2.0


Solution

  • I figured out that I needed a Redirect URI because I made the OAuth2 Key for a Web App rather than a Desktop App. In this case, a redirect uri is not needed.