在我与谷歌的应用程序凭据的Andr​​oid登陆 [英] Android login in my app with google credentials

查看:142
本文介绍了在我与谷歌的应用程序凭据的Andr​​oid登陆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发我想允许用户登录到我的服务器和他的谷歌账户,不要求他的凭据,因为我知道,被保存到的AccountManager类至极的应用程序。 问题是,我不知道该怎么autenticate用户,因为帐户ID只是存储在谷歌的服务器,所以我在哪里可以找到该帐户的ID,我怎么可以用它来autenticate用户?我想请按照下列步骤操作:用户选择存储帐户中的一个,我得到一个ID,它从终端发送到服务器,而我的answere说,他的信任这个用户,在这之后我保存这个ID我服务器并请求身份验证令牌,以谷歌只是使用它在我的服务器和Android设备的应用程序之间。

HI I'm developing an application in wich I want to permit the user to login to my server with his Google account without asking him the credentials because I know that are saved into the AccountManager class. The problem is that I don't know how to autenticate the user because the account ID is just stored in Google's server, so Where can I find an ID for the account and how can I use it to autenticate user? I'd like to follow these steps: user choose one of the stored account, I get an id, send it from the terminal to the server, and I answere that "he trust" this user, after this I save this id in my server and request an auth token to Google just to use it between my server and the application on android device.

推荐答案

这是你想要什么?

List<String> googleAccounts = new ArrayList<String>();
Account[] accounts = AccountManager.get(this).getAccounts();
for (Account account : accounts) {
  if (account.type.equals("com.google")) {
    googleAccounts.add(account.name);
  }
}

您可以看到的ChromeToPhone应用开源由谷歌的code更详细的例子:<一href="http://www.google.com/$c$csearch/p?hl=en#JWblrwroAxw/trunk/android/src/com/google/android/apps/chrometophone/MainActivity.java&l=311" rel="nofollow">http://www.google.com/$c$csearch/p?hl=en#JWblrwroAxw/trunk/android/src/com/google/android/apps/chrometophone/MainActivity.java&l=311

You can see a more detailed example in the code of the ChromeToPhone app open-sourced by Google: http://www.google.com/codesearch/p?hl=en#JWblrwroAxw/trunk/android/src/com/google/android/apps/chrometophone/MainActivity.java&l=311

这篇关于在我与谷歌的应用程序凭据的Andr​​oid登陆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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