[Python] Get only user email address with Google OAuth in Python

Discussão em 'Python' iniciado por Stack, Fevereiro 25, 2025.

  1. Stack

    Stack Membro Participativo

    I am working on a Python web backend. And I have successfully implemented Google OAuth functionality using the following page.

    https://developers.google.com/identity/protocols/oauth2/web-server#python

    Now I just want to know the email address of the logged-in user.

    However, I could not find a function to get only the email address in the google-auth-oauthlib library used in the above page.

    https://github.com/googleapis/google-auth-library-python-oauthlib

    Instead, I added permissions for other APIs that I don't need (e.g. gmail-readonly) and used the function of those APIs to get the user's email address. Of course, I don't like this.

    So this time, I imported the requests library in my code and successfully got the user's email address using the REST API. However, if I was going to use REST API, I would have implemented all the OAuth processes as REST API instead of the google-auth-oauthlib library.

    However, it seems strange no matter how I think about it. It seems like it should be possible using only the google-auth-oauthlib library and without any unnecessary additional permissions. I just can't figure it out. Please help.

    Continue reading...

Compartilhe esta Página