Get all email addresses of user using Google API

前端 未结 4 1734
粉色の甜心
粉色の甜心 2021-02-15 12:20

For my own gmail account, I have multiple email addresses associated with it. For example, I have an email address from my university that is associated with my gmail, and I ca

相关标签:
4条回答
  • 2021-02-15 12:25

    This is possible. However, this has changed since Google announced the deprecation of their Google+ People API, which a lot of folks used to get all the email addresses for a user. The current most voted answer now goes to a 404.

    Google Plus People API Replacement

    Google has replaced the Google Plus People API /plus/v1/people/me with https://developers.google.com/people/ and you’ll want to use the https://www.googleapis.com/auth/user.emails.read profile scope as discussed here as a replacement. The schema is different, so you'll need to change your mapping as well.

    If your app already used the following scopes from the old /plus/v1/people/me your user will not have to re-consent when you switch to the new API:

    email
    profile
    https://www.googleapis.com/auth/plus.login
    https://www.googleapis.com/auth/plus.me
    https://www.googleapis.com/auth/plus.profile.agerange.read
    https://www.googleapis.com/auth/plus.profile.emails.read
    https://www.googleapis.com/auth/plus.profile.language.read
    
    0 讨论(0)
  • 2021-02-15 12:36

    It has been a while since the question was asked. You can use the Google People API to get a user's primary email address and aliases. Here's the documentation. The scope you need to use is: https://www.googleapis.com/auth/user.addresses.read

    This will return all the email addresses for the user and also tell you which is the primary one.

    0 讨论(0)
  • 2021-02-15 12:43

    If you use OAuth to have your users sign-in with their Google accounts (with or without G+) the user will be prompted (by Google) to select which of their accounts they wish to authorize your application to use: https://developers.google.com/accounts/docs/OAuth2Login

    So to directly answer your question, I'm not aware of an API to return that list of users - however you shouldn't need to, Google will take care of this before returning to your application.

    If your user is already logged in, and you wish to give them the ability to change the Google account they are using, I believe it is possible to prompt them again to select the account they are interested in (search for select_account on the link above).

    0 讨论(0)
  • 2021-02-15 12:51

    Your description is a little vague. Are you talking about send-as alias accounts or alternate email accounts?

    Send-as Alias

    Either way, you can interact with the send-as accounts here: Manage Send-as Alias

    Alternate Emails via Admin SDK

    • As for alternate email accounts, they can be accessed via:
      • Admin SDK: https://developers.google.com/admin-sdk/directory/v1/guides/manage-user-aliases?hl=en
      • Google Apps Script: https://developers.google.com/apps-script/reference/gmail/gmail-app#getAliases()
    • Additional info here on how the accounts work.
      • Email addresses associated with your account
      • Alternate email addresses and other Google products
      • Connect other email accounts to your Google Account

    Federated Login

    Also, I'm not exactly sure how you are trying to incorporate this functionality into your site but another area I recommend checking out is Federated Login for Google Account Users. This might also provide you with the functionality you seek.

    Using federated login (also known as federated identity), your website or application can allow visitors to sign in using their Google user accounts. Federated login frees users from having to set up separate login accounts for different websites, and frees you from the task of implementing login authentication measures.

    0 讨论(0)
提交回复
热议问题