How to get user email address using GData?

I am trying to use GData to get the email address, real name and profile URL of the user who has just resolved my site using Google OAuth.

We know how to request it using the Google OpenID stream, but the OpenID stream has a serious limitation that we need to request from the Google Apps user domain before we know where to send them for login. At least using OAuth (or even AuthSub), the user is prompted for which of their Google accounts to log in to.

+4
source share
2 answers

It is still unclear that this is possible, but now we bypass it using the OpenID stream. With the addition of their universal login stream, we no longer have a reason to avoid their OpenID stream.

+1
source

If you select a user contact feed, you can access the authors field, which gives you an email address and name. In addition, the feed id field is represented by the email address of the person to whom the contacts belong.

An example (in Scala) with the changed names, assuming that the user is AuthSub (sorry, I did not transfer my code to OAuth), where you already have a token session:

 scala> val contacts_service = new ContactsService("foo") contacts_service: com.google.gdata.client.contacts.ContactsService = com.google.gdata.client.contacts.ContactsService@3fd1acee scala> contacts_service.setAuthSubToken(token, null) scala> val feedUrl = new URL("https://www.google.com/m8/feeds/contacts/default/full?max-results=10000") feedUrl: java.net.URL = https://www.google.com/m8/feeds/contacts/default/full?max-results=10000 scala> val feed = contacts_service.getFeed(feedUrl, classOf[ContactFeed]) feed: com.google.gdata.data.contacts.ContactFeed = {ContactFeed com.google.gdata.data.contacts.ContactFeed@271a95f8 } scala> feed.getId res13: java.lang.String = user@example.com scala> val p = feed.getAuthors.head p: com.google.gdata.data.Person = com.google.gdata.data.Person@513b4686 scala> p.getEmail res14: java.lang.String = user@example.com scala> p.getName res15: java.lang.String = Example User 
+1
source

Source: https://habr.com/ru/post/1304663/


All Articles