Token invalid - Invalid token: Cannot parse referred token string: Invalid gaia_data.AuthSubToken proto on base64 token

℡╲_俬逩灬. 提交于 2019-12-14 01:21:45

问题


I've strage issue with google spreadsheet via Java application. I had application created which was working without any issue for more than 1 year I even posted an solution for Google API change under Create Spreadsheet using Google Spreadsheet API in Google drive in Java Yesterday I don't know why but it stopped working and now I've only exception:

Exception in thread "main" com.google.gdata.client.GoogleService$SessionExpiredException: Token invalid - Invalid token: Cannot parse referred token string: Invalid gaia_data.AuthSubToken proto on base64 token.

Token invalid - Invalid token: Cannot parse referred token string: Invalid gaia_data.AuthSubToken proto on base64 token. Token invalid - Invalid token: Cannot parse referred token string: Invalid gaia_data.AuthSubToken proto on base64 token. Error 401

at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:570)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:560)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:538)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:536)
at com.google.gdata.client.Service.getFeed(Service.java:1135)
at com.google.gdata.client.Service.getFeed(Service.java:998)
at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:645)
at com.google.gdata.client.Service.getFeed(Service.java:1017)
at SandboxAll.<init>(SandboxAll.java:155)
at SandboxCheck.main(SandboxCheck.java:207)

This is part of the code which was working fine and now it's not:

SpreadsheetService service;
SpreadsheetFeed feed;   
SPREADSHEET_FEED_URL = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full");
        com.google.api.client.json.jackson.JacksonFactory jsonFactory = new com.google.api.client.json.jackson.JacksonFactory();
        String[] SCOPESArray = {"https://spreadsheets.google.com/feeds", "https://spreadsheets.google.com/feeds/spreadsheets/private/full", "https://docs.google.com/feeds"};
        final List SCOPES = Arrays.asList(SCOPESArray);
        GoogleCredential credential = new GoogleCredential.Builder()
                .setTransport(httpTransport)
                .setJsonFactory(jsonFactory)
                .setServiceAccountId("xxxxxx@developer.gserviceaccount.com")
                .setServiceAccountScopes(SCOPES)
                .setServiceAccountPrivateKeyFromP12File(p12)
                .build();
        service = new SpreadsheetService("Sandbox");
        service.setOAuth2Credentials(credential);
        service.setReadTimeout(160000);
        service.setConnectTimeout(16000);
        --->feed = service.getFeed(SPREADSHEET_FEED_URL, SpreadsheetFeed.class); <---

The exception is throw on feed = service.getFeed(SPREADSHEET_FEED_URL, SpreadsheetFeed.class); I was looking for any answer in the internet but could now find anythig. Did google again changed something ? I've recreate my account this this did not help.


回答1:


(I don't want to edit my answer so anyone with the same issue will be able to try to check the same solution as I did) I don't know but in my case setting Scope only for feed

 String[] SCOPESArray = {"https://spreadsheets.google.com/feeds"/*, "https://spreadsheets.google.com/feeds/spreadsheets/private/full", "https://docs.google.com/feeds","https://www.googleapis.com/auth/drive"*/};

helped. When I was displaying refreshToken()

System.out.println(credential.refreshToken());

I've notice that some of the feeds had false value.



来源:https://stackoverflow.com/questions/40278900/token-invalid-invalid-token-cannot-parse-referred-token-string-invalid-gaia

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!