2010-10-12 42 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

相關問題