分享谷歌Android客户端API和S preadSheet API 3.0之间的身份验证/令牌令牌、身份验证、客户端、Android

2023-09-06 08:22:11 作者:Μr贝戋

我在我的项目中的两个模块。首先是负责创建一个文件夹,并在谷歌驱动器A S preadsheet。二是负责在s preadsheet插入行。第一个模块,我指的是样品此处。对于第二个模块,我指的例子这里。有什么办法,我可以使用第二个模块中使用GoogleAPIClient第一个模块中进行验证,但不尝试再次进行身份验证。也对信息的第二模块中的服务内的的AsyncTask运行。任何建议如何做到这一点?

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?

推荐答案

终于结束了使用如下:

   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.