使用 Google 帐户登录 Android 应用程序 [英] Using Google account to log in to an Android Application

查看:61
本文介绍了使用 Google 帐户登录 Android 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Android 上开发一个应用程序,我希望允许用户使用他们的 Google 帐户登录.我怎样才能做到这一点?

I’m developing an application on Android and I want to allow users to log in with their Google account. How can I achieve this?

推荐答案

您可能希望像某些应用程序一样使用您设备中已配置的 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/Extras/Google Play Services

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

只需简单的步骤

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

这是另一个可以很好地解释过程的链接 -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. 后端服务器通过此 url "https://www.googleapis.com/oauth2/v1/userinfo?access_token=ACCESS_TOKEN"
  3. Next 后端服务器响应应用是否让用户登录.

下面是上面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";

在那个样本中

这篇关于使用 Google 帐户登录 Android 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆