English 中文(简体)
How does one retrieve the email address of a user with GData?
原标题:

I m trying to use GData to retrieve the email address, real name, and profile URL of the user that just authorized my site using Google OAuth.

We know how to request it using Google s OpenID flow, but the OpenID flow has the severe limitation that we have to ask for a Google Apps user s domain before we know where to send them to log in. At least using OAuth (or even AuthSub), the user gets prompted for which of their Google accounts to log in.

最佳回答

Still not clear that this is possible, but we now work around it by using the OpenID flow. With the addition of their universal login flow, we no longer have reason to avoid their OpenID flow.

问题回答

If you fetch the user s contacts feed, you can access the authors field which gives you email and name. Additionally, the feed s id field appears to be the email address of the person who owns the contacts.

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

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




相关问题
Authlogic-oid with ONLY OpenID

I am implementing an internal site, for which I want our company s OpenID server to be the only means of registering and logging in. To be more specific, I don t even want a normal email and password/...

Best Coldfusion Library for OpenID [closed]

I am getting ready to start a project that requires using OpenID within Coldfusion 8. I have found a number of different options and was wondering what has worked the best, get s the most support, ...

authlogic auto_register feature using my options

I have auto registration working with authlogic using gaizka s version of authlogic_openid which I found on Github since pelle s original addition of the feature seemed to cause issues. http://...

Requesting email address from OpenID provider in PHP

What s the simplest way to request an email address from an OpenID provider? Is there a good PHP library that simplifies this problem? I know that providers implement things differently. I ve heard ...

Got a strange OpenID. How can I change it?

(I am sorry, I wanted to ask this question on "meta" first, but it says there that I "can t post my question there because I don t have an OpenID") Hello, I am just a new user here and don t ...

热门标签