首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google任务身份验证错误

Google任务身份验证错误
EN

Stack Overflow用户
提问于 2011-11-29 23:03:35
回答 1查看 2.9K关注 0票数 3

我已经开始编写一个安卓应用程序,它实现了一个ListView和一个简单的数据库,并提供了从特定的谷歌账户接收任务,然后将它们添加到ListView的机会。

我使用这个TutorialTasks API来实现代码,但它不起作用,网上也没有太多其他的教程。这是我的Start-Activity的一个片段。

我在手机上只创建了一个账号,所以我省略了‘选择账号’-对话框:

代码语言:javascript
复制
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'-Method:

代码语言:javascript
复制
    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();
        }
    }

一切都很正常-我得到了一个令牌,有一个服务对象和一个帐户对象-但当我们

代码语言:javascript
复制
TaskLists taskLists = service.tasklists.list().execute();

它抛出一个异常,什么也没有发生,所以我猜TaskLists对象没有初始化,但是我不知道为什么“它无法响应”(LogCat)。

下面是LogCat:

代码语言:javascript
复制
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之间的不同之处,如果有人能帮助我就太好了,因为我不知道我还能在哪里找到关于这个主题的帮助。非常感谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-12-08 17:46:43

对于每个遇到相同问题的人,请尝试将令牌保存在共享首选项中,并在每次启动应用程序时使其无效,并由于帐户管理器的错误而生成一个新令牌;我的问题可以通过以下方式解决:请参阅此:https://groups.google.com/group/google-tasks-api/browse_thread/thread/6d65116019baf122/81293191c46ebdc6?lnk=gst&q=401#81293191c46ebdc6

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8312984

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档