【问题标题】:single google account authtoken for Multiple Google Data API in AndroidAndroid 中多个 Google 数据 API 的单个 google 帐户 authtoken
【发布时间】:2012-02-17 11:19:35
【问题描述】:

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

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

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

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

TYIA。

【问题讨论】:

    标签: android google-data-api auth-token


    【解决方案1】:

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

    看看sample code for using the client libraries,你能做这样的事情吗:

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

    当您第一次执行此操作时,用户将收到一个请求访问其日历的弹出窗口。一旦获得批准,应该会出现另一个弹出窗口,要求获得 Docs 的许可。一旦获得批准,弹出窗口将不再出现(除非用户可能重新安装您的应用程序)。所以我认为你不需要担心任何事情。只需确保您第一次尝试在 UI 线程中而不是在后台进程中获取 authTokens。在后台进程中,不会出现弹出窗口。

    【讨论】:

    • 感谢您分享您的见解,我会让这段代码 sn-p 工作
    猜你喜欢
    • 1970-01-01
    • 2011-04-22
    • 2019-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多