Sush
Sush

Reputation: 6899

Sharing authentication/token between Android Google Client API and SpreadSheet API 3.0

I have two modules in my project. The first is responsible for creating a folder and a spreadsheet in the google drive. The second is responsible for inserting rows in the spreadsheet. For the first module I am referring to the sample here. For Second module I am referring the examples here. Is there any way I can use the authentication done in the first module using the GoogleAPIClient in the second module without trying to authenticate again. Also for information the second module runs in an AsyncTask inside a service. Any suggestion how to do this?

Upvotes: 1

Views: 591

Answers (1)

Sush
Sush

Reputation: 6899

Finally ended up using below :

   String SCOPE = "oauth2:https://docs.google.com/feeds/ https://docs.googleusercontent.com/ https://spreadsheets.google.com/feeds/"

   accessToken = GoogleAuthUtil.getTokenWithNotification(context,HelperUtils.getStringFromPrefs(context, AppConstants.SP_ACCOUNT_NAME,""), SCOPE,null);
        Log.d(TAG,"AccessToken : " + accessToken);
    SpreadsheetService service = new SpreadsheetService("V1");
    service.setProtocolVersion(SpreadsheetService.Versions.V3);
    service.setHeader("Authorization", "Bearer " + accessToken);

Used the account name selected from the account picker in the first module.

Upvotes: 1

Related Questions