5

你好android爱好者,我正在努力寻找解决这个问题的方法。我计划访问用户的 Google 日历和 Google 文档(使用 google-api-java-client-v1.6.0)。我可以通过 AccountManager 访问用户的 Google 帐户,但由于这个原因,我没有搞砸请求 authToken 对用户进行身份验证:

当用户确认应用程序访问他的 Google 帐户时,我将如何在单个 Activity 中处理对 Docs 和 Cal 的多个 authToken 请求?

在我的应用程序中,当用户允许访问用户帐户时,Google Docs 和 Cal 位于后台运行的不同选项卡上。

任何链接教程将不胜感激。

蒂亚。

4

1 回答 1

2

If I interpret you correctly, you are wondering how to handle the fact that you need one authToken for Calendar, and one authToken for Docs?

Looking at some sample code for using the client libraries, could you do something like this:

private final static String CAL_AUTH_TOKEN_TYPE = "cl";
private final static String DOCS_AUTH_TOKEN_TYPE = "writely"; // Not sure this is correct

// This will ask the user for permissions the first time
Bundle docsBundle = manager.getAuthToken(account, DOCS_AUTH_TOKEN_TYPE, true, null, null);
Bundle calBundle = manager.getAuthToken(account, CAL_AUTH_TOKEN_TYPE, true, null, null);

// Do whatever syncing you need
doWork(docsBundle, calBundle);

When you do this the first time, the user will get a popup requesting access to his Calendar. Once approved, another popup should appear asking permission for Docs. Once approval is given, the popups never appear again (unless the user maybe re-installs your app). So I don't think you need to worry about anything. Just make sure that you try to get the authTokens the first time in your UI-thread and not in a background process. In a background process, a popup window will not appear.

于 2012-02-24T16:14:56.037 回答