Get all email addresses of user using Google API

早过忘川 提交于 2019-12-13 11:43:01

问题


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 can send emails from my gmail as if they are coming from my university email address.

I'm reading up on the Google APIs, and I see that I can get a user's gmail address, but can I also get any other email address that is associated with their gmail account?

When a user logs in to my site, I'd like to present them with a list of the gmail-associated email addresses and let them select the one they would like to use.

EDIT: Thanks everyone for the answers, but I don't think any of them answers the question. I've been playing with Google's OAuth playground. It is strange that I can get lots of very personal information (a list of a user's contacts and even received emails) but I can't get the user's alternative email addresses.


回答1:


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.




回答2:


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.




回答3:


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).




回答4:


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


来源:https://stackoverflow.com/questions/20870445/get-all-email-addresses-of-user-using-google-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!