Sharing authentication/token between Android Googl

2019-06-02 08:08发布

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?

1条回答
Ridiculous、
2楼-- · 2019-06-02 08:52

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.

查看更多
登录 后发表回答