从的authToken中的AccountManager Android客户端不再工作 [英] AuthToken from AccountManager in Android Client No Longer Working

查看:125
本文介绍了从的authToken中的AccountManager Android客户端不再工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是pretty的激怒。我试图建立一个回合制多人在线游戏,使用谷歌应用引擎用Java Android作为服务器。

I'm pretty exasperated. I'm attempting to build a turn-based multiplayer online game for Android using Google App Engine in Java as the server.

他们就像一个完美的结合。机器人需要一个谷歌帐户,GAE采用的是谷歌帐户进行身份验证,而被自由和可扩展性。

They seem like a perfect fit. Android requires a Google account, and GAE uses a Google account for authentication, while being free and scalable.

所以,我在假期前能够从使用新的AccountManager API在Android 2.0的我的Andr​​oid客户端得到验证我的GAE应用程序。下面code可以让你访问用户的谷歌帐户的authToken,然后用它进行身份验证,从而使用户不必手动输入他们的帐户的用户名和密码:

So before the holidays I was able to get authentication to my GAE app from my Android client using the new AccountManager API in Android 2.0. The following code allows you to access the AuthToken of the user's Google account and then use it for authentication, so that the user does not have to manually enter their account username and password:

   AccountManager mgr = AccountManager.get(this); 
   Account[] accts = mgr.getAccountsByType("com.google"); 
   Account acct = accts[0];
   AccountManagerFuture<Bundle> accountManagerFuture = mgr.getAuthToken(acct, "ah", null, this, null, null);
   Bundle authTokenBundle = accountManagerFuture.getResult(); 
   String authToken = authTokenBundle.get(AccountManager.KEY_AUTHTOKEN).toString();

我就能够追加造成的authToken字符串相应的URL,并得到了有效的cookie,我可以再使用的所有进一步的请求。唯一的一点是,有时上周刚刚停止工作对我来说。现在,当我尝试使用的authToken从上面的code,我没有得到一个cookie回来,我的code抛出一个NullPointerException异常失踪的cookie。

I was then able to append the resulting AuthToken string to the appropriate URL and get a valid cookie which I could then use for all further requests. Only thing is, sometime last week it just stopped working for me. Now when I try to use the AuthToken from the above code, I don't get a cookie returned and my code throws a NullPointerException for the missing cookie.

当我回到老路上,当用户手动输入他们的谷歌的用户名和密码,我从https://www.google.com/accounts/ClientLogin得到的authToken,它工作得很好

When I go back to the old way, when the user was manually entering in their Google username and password and I get the AuthToken from "https://www.google.com/accounts/ClientLogin", it works just fine.

请告诉我,有人在那里建有一个Android客户端使用的authToken从用户的手机上的谷歌帐户谷歌App Engine的应用程序,并给我一些线索,这是为什么不再工作。

Please tell me someone out there has built an Android client for a Google App Engine app using the AuthToken from the Google account on the user's phone, and give me some clue as to why this is no longer working.

我真的很想来完成这项工作。我的替代品,要求用户输入他们的凭证(这是笨重,而且他们不应该这样做),或与服务器的另一个解决方案去。

I'd really like to make this work. My alternatives are to require the user to enter their credentials (which is clunky, and which they shouldn't have to do), or going with another solution for the server.

在此先感谢。

推荐答案

得到帮助,这从谷歌工程师。原来我的authToken届满。我最初得到的实施工作在十二月初(9日是精确的)。显然什么的AccountManager做的是缓存中的authToken,所以我使用了相同的的authToken自12月9得到了。当我回来的假期就已经过期了。

Got help for this from a Google engineer. Turns out my authToken was expired. I had initially gotten the implementation working in early December (the 9th to be exact). Apparently what the AccountManager does is cache the authToken, so I had been using the same authToken since Dec. 9th. When I got back from the holidays it had expired.

要解决这个问题,我现在请getAuthToken,然后调用invalidateAuthToken在该令牌,然后再次调用getAuthToken。这会产生一个有效的authToken和工作得很好,哪怕是一点点笨重,将是不必要的,如果的AccountManager刚刚得到一个新的authToken每一次,或做了检查,看是否缓存一人到期。

To solve the issue, I now call getAuthToken, then call invalidateAuthToken on that token, then call getAuthToken again. This generates a valid authToken and works just fine, even if it is a little clunky and would be unnecessary if AccountManager just got a fresh authToken each time, or did a check to see if the cached one was expired.

请注意,您一定不要混淆令牌类型与帐户类型:invalidateAuthToken必须调用com.google,而不是啊,否则它将静默失败

Note that you must not mix up token type with account type: invalidateAuthToken must be called with "com.google" instead of "ah" or it will silently fail.

这篇关于从的authToken中的AccountManager Android客户端不再工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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