single google account authtoken for Multiple Google Data API in Android

343 views Asked by At

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.

1

There are 1 answers

1
Jonas Kalderstam On

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.