且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Google帐户登录Android应用程序

更新时间:2023-10-11 16:03:16

您可能希望像某些应用一样使用已在设备中配置的Google帐户之一对用户进行身份验证,为此请点击以下链接-

You might want to authenticate the user using one of the google account already configured in your device like some of the apps do, for that follow the below link -

对OAuth2服务进行身份验证"- http://developer.android.com /training/id-auth/authenticate.html

"Authenticating to OAuth2 Services" - http://developer.android.com/training/id-auth/authenticate.html

从Google下载示例-Android SDK Manager/附加/Google Play服务

Download Sample from Google - Android SDK Manager/Extras/Google Play Services

只需简单的步骤即可

  1. 显示您手机中的帐户列表
  2. 从选定的帐户生成访问令牌
  3. 通过联系Google服务(单独调用)从访问令牌中获取帐户名,以告知其已通过身份验证.

这是另一个很好地说明过程的链接- http://android-developers.blogspot .in/2013/01/verifying-back-end-calls-from-android.html

This is another link which is good in explaining the process - http://android-developers.blogspot.in/2013/01/verifying-back-end-calls-from-android.html

您可以按照以下步骤在应用程序中登录

you can follow below steps for Login in your app

  1. 您将把生成的访问令牌发送到您的后端服务器
  2. 后端服务器通过以下网址联系Google服务来检查访问令牌是否有效:" https://www.googleapis.com/oauth2/v1/userinfo?access_token=ACCESS_TOKEN "
  3. 下一台后端服务器是否响应应用程序是否使用户登录.

下面是"userinfo"调用上方的响应格式

Below is response format of above "userinfo" call

{
 "id": "ID",
 "name": "NAME",
 "given_name": "GiVEN NAME",
 "family_name": "FAMILY_NAME",
 "link": "https://plus.google.com/ID",
 "picture": "https://PHOTO.jpg",
 "gender": "GENDER",
 "locale": "LOCALE"
}

如果您想要电子邮件ID 以及该回复,则必须进行修改

If you want Email id along with that response you have to modify

SCOPE ="oauth2: https://www.googleapis.com/auth/userinfo.profile ";

SCOPE = "oauth2:https://www.googleapis.com/auth/userinfo.profile";

SCOPE ="oauth2: https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email ;

SCOPE = "oauth2:https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email";

在该样本中