- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我已经开始编写一个 Android 应用程序,它实现了一个 ListView 和一个简单的数据库,并提供了从特定 Google 帐户接收任务并将其添加到 ListView 的机会。
我用了这个Tutorial和 Tasks API实现代码,但它不起作用,网络上也没有很多其他教程。这是我的开始 Activity 的 fragment 。
我在手机上只创建了一个帐户,所以我省略了“选择帐户”对话框:
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();
}
}
一切正常 - 我得到一个 token ,有一个服务对象和一个帐户对象 - 但是当我们到达时
TaskLists taskLists = service.tasklists.list().execute();
它抛出一个异常并且什么也没有发生,所以我猜 TaskLists - 对象没有初始化,但我不知道为什么“它无法响应”(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 之间的区别在哪里,如果有人能帮助我,那就太好了,因为我不知道我还能在哪里找到关于这个主题的帮助。非常感谢。
最佳答案
遇到同样问题的各位,尝试将token保存在Shared Preferences中,每次启动应用时将其失效,并由于Account Manager的bug而生成一个新的;我的问题可以这样解决:看到这个: https://groups.google.com/group/google-tasks-api/browse_thread/thread/6d65116019baf122/81293191c46ebdc6?lnk=gst&q=401#81293191c46ebdc6
关于android - Google Tasks 身份验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8312984/
这个问题在这里已经有了答案: Why use async and return await, when you can return Task directly? (8 个答案) 关闭 6 年前。
这个问题在这里已经有了答案: Are the days of passing const std::string & as a parameter over? (13 个答案) 关闭 8 年前。 我
我有一组标记为执行的通用任务。当任务完成时(使用 Task.WaitAny ),我将其添加到 ObservableCollection 中. 但是,问题出在 Task.WaitAny(...)行,上面
经过几个小时的努力,我在我的应用程序中发现了一个错误。我认为下面的 2 个函数具有相同的行为,但事实证明它们没有。 谁能告诉我引擎盖下到底发生了什么,以及为什么它们的行为方式不同? public as
这也与 Python 的导入机制有关,特别是与在函数内使用 import 有关。使用 Python 2.7.9 和 Fabric 1.10.0,创建以下三个文件: fabfile.py: from a
我有一个 Web API Controller (ASP.NET Core 5)。我的一些 API 是异步的,而其中一些不是。我接下来的问题是:使用 public **Task** WebApiMet
我们有类似下面的内容 List uncheckItems = new List(); for (int i = 0; i new Task(async () => await Process
我的代码没问题,但我想知道哪种风格更好,你会怎么看,我正在玩异步方法。 让我建立上下文: Parallel.ForEach(xmlAnimalList, async xml => {
这两种使用 await 的形式在功能上有什么区别吗? string x = await Task.Factory.StartNew(() => GetAnimal("feline")); Task m
我刚刚看到 3 个关于 TPL 使用的例程,它们做同样的工作;这是代码: public static void Main() { Thread.CurrentThread.Name = "Ma
考虑以下代码: public void CacheData() { Task.Run((Action)CacheExternalData); Task.Run(() => CacheE
Task> GetTaskDict() { return Task.FromResult(new Dictionary () ); } 此代码无法编译,因为我们无法在 Task> 到 Tas
我正在使用 ASP.NET 5 RC1 _MyPartial @model MyViewModel @using (Html.BeginForm())
当我尝试在 VS Code 中构建 C 任务时,它显示以下消息: 输出仅显示:The task provider for "C/C++" tasks unexpectedly provided a t
一些背景: 基本上归结为我希望能够在当前线程中“执行”任务。为什么? -我有一个任务创建程序例程,有一次我希望任务在后台任务中立即执行,而其他时候我希望使用 IOmniThreadPool 安排任务。
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我试图将run-sequence添加到我的gulp工作流程中,但是每次尝试执行使用run-sequence的任务时,都会出现此错误: 任务未配置为gulp上的任务。 根据运行序列的来源,这是由以下te
此代码在VS2015中给出了编译时错误 Error CS0266 Cannot implicitly convert type 'System.Threading.Tasks.Task' to 'Sy
我正在尝试通过我的代码通过Google登出: suspend fun signOut(context: Context): Boolean = with(Dispatchers.IO) { t
谁能解释一下这两种说法的区别: Task bTask = backup.BackupCurrentDatabaseAsync() .ContinueWith(_ => CompressArch
我是一名优秀的程序员,十分优秀!