Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6240941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:39:53+00:00 2026-05-24T11:39:53+00:00

In a Python web application, I am able to connect to Gmail using OAuth

  • 0

In a Python web application, I am able to connect to Gmail using OAuth and IMAP. OAuth uses whichever Google account you’re currently signed into simply and asks you to grant access to the web app. However, it doesn’t provide an API to actually retrieve that account’s email address.

The problem is, even though the user grants access with OAuth, to interface with Gmail, you still need to explicitly provide the email address in your IMAP connection URL:

https://mail.google.com/mail/b/[your-email]/imap/

Because of this, the web application has to ask the user for their email address and ask them to grant access from Gmail with OAuth. What’s worse is the email address they enter may not match the email of the account they grant access with, causing the app to fail.

Is there a way to get your email address using OAuth so you can put it in that URL without asking the user for it? I tried looking at this answer but Google returns a Bad Request whenever I use both https://mail.google.com/ and https://www.googleapis.com/auth/userinfo#email as my scope.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T11:39:54+00:00Added an answer on May 24, 2026 at 11:39 am

    What you’re after is the Google Contacts API. If you’re authorizing via OAuth you’re probably currently asking for permission to access the gmail scope:

    https://mail.google.com/mail/feed/atom
    

    You will also need to ask for permission for the contacts scope:

    https://www.google.com/m8/feeds/
    

    Once you have that, you can make a GET request similar to the following:

    https://www.google.com/m8/feeds/contacts/default/full?max-results=1
    

    This should return a bunch of xml, here are some relevant bits:

    <?xml version="1.0" encoding="UTF-8"?>
    <feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:gContact="http://schemas.google.com/contact/2008" xmlns:batch="http://schemas.google.com/gdata/batch" xmlns:gd="http://schemas.google.com/g/2005" gd:etag="W/&quot;CEcMRX0_eCp7ImA9WhdRF00.&quot;">
    <id>joebloggs@gmail.com</id>
    ...
    <author>
      <name>Joe Bloggs</name>
      <email>joebloggs@gmail.com</email>
    </author>
    ...
    </feed>
    

    As you can see you can find the authorized users’ email in a couple of places.

    If you’re using OAuth you might also want to have a look at the Google OAuth playground, I’ve found it very handy: http://googlecodesamples.com/oauth_playground/index.php. If you decide to use OAuth2 there is equivalent tool at https://code.google.com/oauthplayground

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a Python/Django web application that uses OAuth (for the TwitterAPI, not
I am working on a web application using Python (Django) and would like to
I'm using Pylons (a python framework) to serve a simple web application, but it
I am just beginning to start learning web application development, using python. I am
I am writing a simple Python web application that consists of several pages of
I'm writing a web application in Python, intended for use by teachers and pupils
Almost every Python web framework has a simple server that runs a wsgi application
I'm looking for an open-source pastebin web-application written in either Python or Perl. I
I'm writing a reasonably complex web application. The Python backend runs an algorithm whose
For my web application running on LAMP, I need to be able to deploy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.