2011-11-29 72 views
3

我已經開始編寫實現ListView和簡單數據庫的Android應用程序,並提供從特定Google帳戶接收任務並將其添加到ListView的機會。Google Tasks身份驗證錯誤

我用這個TutorialTasks API來實現代碼,但它不起作用,網上沒有很多其他的教程。這是我的開始活動的片段。

我的手機上創建一個帳戶,所以我離開了 '選擇Accounts'-對話框:

googleAccountManager = new GoogleAccountManager(RememberMe.this); 
Account[] accounts = googleAccountManager.getAccounts(); 
account = accounts[0]; 
googleAccountManager.manager.getAuthToken(account, AUTH_TOKEN_TYPE, null, this, new AccountManagerCallback<Bundle>() 
      { 
       public void run(AccountManagerFuture<Bundle> future) 
        { 
         try 
          { 
           // If the user has authorized your application to use the tasks API 
           // a token is available. 
           String token = future.getResult().getString(AccountManager.KEY_AUTHTOKEN); 
           HttpTransport transport = AndroidHttp.newCompatibleTransport(); 
           GoogleAccessProtectedResource googleAccessProtectedResource = new GoogleAccessProtectedResource(token); 
           service = new Tasks(transport, googleAccessProtectedResource, new JacksonFactory()); 
           service.setKey("AIzaSyDAnO-UGa_zJnqftSVTHnvoHDp8Tfrmtko"); 
           service.setApplicationName("Remember Me"); 



           receivingTasks(); 
           // Now you can use the Tasks API... 

          } 
         catch (OperationCanceledException e) 
          { 
           // TODO: The user has denied you access to the API, you should handle that 
           Log.w(TAG, "synchronize - Catch OperationCanceled Exception"); 
          } 
         catch (Exception e) 
          { 
           Log.w(TAG, "synchronize - Catch Exception e"); 
          } 
        } 
      }, null); 

這裏是' receiveTasks'法:

public void receivingTasks() 
    { 
     try 
     { 
      TaskLists taskLists = service.tasklists.list().execute(); 
      for (TaskList taskList : taskLists.getItems()) 
      { 
        Log.w(TAG, "" + taskList.getTitle()); 
      } 
     } 
     catch (IOException e) 
     { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    } 

一切的工作罰款 - 我得到一個令牌,有一個服務對象和一個帳戶對象 - 但當我們得到

TaskLists taskLists = service.tasklists.list().execute(); 

它拋出一個例外,沒有任何反應,所以我猜TaskLists - Object沒有初始化,但我不知道爲什麼「它無法響應」(LogCat)。

這裏的logcat的:

11-29 15:57:58.848: W/DefaultRequestDirector(2878): Authentication error: Unable to respond to any of these challenges: {authsub=WWW-Authenticate: AuthSub realm="https://www.google.com/accounts/AuthSubRequest" allowed-scopes="https://www.googleapis.com/auth/tasks,https://www.googleapis.com/auth/tasks.readonly"} 

11-29 15:57:58.858: W/System.err(2878): com.google.api.client.http.HttpResponseException: 401 Unauthorized 

11-29 15:57:58.858: W/System.err(2878):  at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:669) 

11-29 15:57:58.868: W/System.err(2878):  at com.google.api.services.tasks.Tasks$RemoteRequest.execute(Tasks.java:1571) 

11-29 15:57:58.868: W/System.err(2878):  at com.google.api.services.tasks.Tasks$Tasklists$List.executeUnparsed(Tasks.java:1277) 

11-29 15:57:58.868: W/System.err(2878):  at com.google.api.services.tasks.Tasks$Tasklists$List.execute(Tasks.java:1262) 

我也想知道教程和API之間的不同的是,這將是巨大的,如果有人可以幫助我,因爲我不知道還有什麼地方我能找到有關這個話題的幫助。 非常感謝。

回答