姓名,来自Google OAuth API的电子邮件

Ash*_*Ash 21 oauth google-api

我想允许用户在网站上使用谷歌登录并收集他们的姓名和电子邮件地址,但我找不到关于google的API的用户信息范围的任何文档:https://www.googleapis.com/auth/userinfo.

谢谢

Jon*_*abe 65

这是获取姓名和电子邮件的更好方法.

将范围设置为:

https://www.googleapis.com/auth/userinfo.email

https://www.googleapis.com/auth/userinfo.profile

并使用端点:

https://www.googleapis.com/oauth2/v1/userinfo?alt=json

那将为您提供所需的一切!

  • 将范围与空间分开 - 对于现在可能知道的人 (6认同)
  • 谢谢,这正是我所需要的.对于其他人的参考,这个http://googlecodesamples.com/oauth_playground/index.php对于确定您的Google OAuth范围非常有帮助. (3认同)

alf*_*kim 8

我使用 http://www-opensocial.googleusercontent.com/api/people/https://www.googleapis.com/auth/userinfo#email作为请求令牌的范围.

受保护的资源网址为 https://www-opensocial.googleusercontent.com/api/people/@me/@self,以获取当前用户的数据.

我得到了用户的G +个人资料和姓名.我还没有收到用户的电子邮件,但我认为我很接近


Des*_*Lua 8

使用Google Python API检索OAuth userinfo:

https://developers.google.com/api-client-library/python/start/installation https://developers.google.com/api-client-library/python/guide/aaa_oauth

import httplib2
from apiclient.discovery import build
from oauth2client.client import OAuth2WebServerFlow

http = httplib2.Http()
http = credentials.authorize(http)

users_service = build('oauth2', 'v2', http=http)
user_document = users_service.userinfo().get().execute()
Run Code Online (Sandbox Code Playgroud)

  • 为什么要把这个答案投票?工作完美,解决了我的问题.我正在使用G + API,我也想要用户的电子邮件,我只需要用oauth2做一个请求.谢谢 ! (2认同)