2010-10-12 38 views
3

我有一个Android应用程序,我想连接到基于Google App Engine的服务器。我可以从AccountManager获取身份验证令牌。看来我应该做的下一件事是与一个验证页面交谈以获取一个cookie。这里继真棒说明:http://blog.notdot.net/2010/05/Authenticating-against-App-Engine-from-an-Android-app 我觉得我的网址应该是:什么是从基于GAE的应用程序获取Auth Cookie的正确URL

https://MYAPP.appspot.com/_ah/login?continue=http://localhost/&auth=CrAZYl000ngToken 

但不是重定向,我得到一个500服务器错误:

Error: Server Error 

The server encountered an error and could not complete your request. 
If the problem persists, please report your problem and mention this error message 
and the query that caused it. 

是什么回事?我应该去的网址是什么?或者,也许我在做别的事情呢?

+0

它仍然适合你吗?我已开始将重定向指向https://www.google.com/accounts/ServiceLogin?service=ah&passive=true & continue = https://appengine.google.com/_ah/conflogin%3Fcontinue%3D & ltmpl = gm & shdf = OTHERCRAZYTOKEN' – 2014-02-12 20:37:51

回答

9

好的,这个网址毕竟没有错。问题在于令牌已过期。我能够通过无效和重新获取令牌来解决这个问题。

private class GetAuthTokenTask extends AsyncTask<Account, Object, String> { 

    @Override 
    protected String doInBackground(Account... accounts) { 
     AccountManager manager = AccountManager.get(getApplicationContext()); 
     Account account = accounts[0]; 
     String token = this.buildToken(manager, account); 
     manager.invalidateAuthToken(account.type, token); 
     return this.buildToken(manager, account); 
    } 

    private String buildToken(AccountManager manager, Account account) { 
     try { 
      AccountManagerFuture<Bundle> future = manager.getAuthToken (account, "ah", false, null, null); 
      Bundle bundle = future.getResult(); 
      return bundle.getString(AccountManager.KEY_AUTHTOKEN); 
     } catch (OperationCanceledException e) { 
       Log.w(TAG, e.getMessage()); 
     } catch (AuthenticatorException e) { 
       Log.w(TAG, e.getMessage()); 
     } catch (IOException e) { 
       Log.w(TAG, e.getMessage()); 
     } 
     return null; 
    } 

    protected void onPostExecute(String authToken) { 
     new GetCookieTask().execute(authToken);  
    } 
} 
+0

这确实解决了我的问题后3小时的麻烦!我使auth令牌无效,但使用null作为token参数。这是我能发现的唯一区别。但是,当用户操作需要接受登录时,你如何处理这个案例,那么这个捆绑包应包含一个意图。 – Rikard 2011-10-04 19:24:00

相关问题