Android 中多个 Google 数据 API 的单个 Google 帐户身份验证令牌

发布于 2024-12-28 09:52:38 字数 351 浏览 2 评论 0原文

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

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

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

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

蒂亚。

Hello android enthusiast, i'm struggling to find solution to this problem. I'm planning to access the user's Google Calendar and Google Documents,(using google-api-java-client-v1.6.0). I can access the user's Google account through AccountManager but I didn't mess up on requesting authToken to authenticate the user for this reason:

How will I handle multiple authToken request for Docs and Cal in a single Activity when the user confirms the application to access his Google Accounts?

In my application, Google Docs and Cal are on different tabs running on background the moment user allows the access of user's account.

any link tutorials would be greatly appreciated.

TYIA.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森林迷了鹿 2025-01-04 09:52:38

如果我的解释正确的话,您想知道如何处理日历需要一个 authToken,文档需要一个 authToken 的事实?

查看一些使用客户端库的示例代码,你能做这样的事情吗:

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);

当你第一次这样做时,用户将看到一个弹出窗口,请求访问他的日历。一旦获得批准,就会出现另一个弹出窗口,询问文档的许可。一旦获得批准,弹出窗口就不会再出现(除非用户重新安装您的应用程序)。所以我认为你不需要担心任何事情。只需确保您第一次尝试在 UI 线程中获取 authToken,而不是在后台进程中获取。在后台进程中,不会出现弹出窗口。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文