2011-11-29 73 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之间的不同的是,这将是巨大的,如果有人可以帮助我,因为我不知道还有什么地方我能找到有关这个话题的帮助。 非常感谢。

回答