如何使用 GData 检索用户的电子邮件地址?

发布于 2024-08-26 10:18:30 字数 223 浏览 9 评论 0原文

我正在尝试使用 GData 检索刚刚使用 Google OAuth 授权我的网站的用户的电子邮件地址、真实姓名和个人资料 URL。

我们知道如何使用 Google 的 OpenID 流程请求它,但 OpenID 流程有一个严重的限制,即我们必须先询问 Google Apps 用户的域,然后才能知道将他们发送到何处登录。至少使用 OAuth(甚至 AuthSub) ,系统会提示用户输入要登录的 Google 帐户。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苏别ゝ 2024-09-02 10:18:31

仍不清楚这是否可行,但我们现在通过使用 OpenID 流程来解决它。随着他们的通用登录流程的增加,我们不再有理由避开他们的 OpenID 流程。

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.

寄风 2024-09-02 10:18:31

如果您获取用户的联系人供稿,则可以访问为您提供电子邮件和姓名的authors 字段。此外,提要的 id 字段似乎是联系人所有者的电子邮件地址。

名称已更改的示例(在 Scala 中),假设 AuthSub 的用户(抱歉,我没有将代码迁移到 OAuth),其中您已经拥有会话令牌

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 = [email protected]

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 = [email protected]

scala> p.getName
res15: java.lang.String = Example User

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 = [email protected]

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 = [email protected]

scala> p.getName
res15: java.lang.String = Example User
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文