Trying to refresh a token to access Google Contacts where user has approved access_type=offline.
This works and I get an access token that works for a while. At some point that token expires and I need to refresh. It appears that my refresh token is good (ya29.AHES6ZRhvyWAx4z_8_uJnBuI6tEELZqBDdh54Ti6ydvb5f0), but the access.getAccessToken() returns null after a call to access.refresh(). Here is the code:
HttpTransport TRANSPORT = new NetHttpTransport();
JsonFactory JSON_FACTORY = new JacksonFactory();
GoogleAccessProtectedResource access = new GoogleAccessProtectedResource(parent.accessTokenGC,
TRANSPORT, JSON_FACTORY, GCGlobals.clientID, GCGlobals.clientSecret, parent.refreshTokenGC);
HttpRequestFactory rf = TRANSPORT.createRequestFactory(access);
GenericUrl contactURL = new GenericUrl(GCGlobals.baseScope + "contacts/default/full?max-results=5000&alt=json");
HttpRequest req = rf.buildGetRequest(contactURL);
GoogleHeaders header = new GoogleHeaders();
header.setContentType("application/json");
header.set("GData-Version", "3");
req.setHeaders(header);
try {
res = req.execute();
} catch (com.google.api.client.http.HttpResponseException ee) {
// try to refresh the token
try {
System.out.println(ee.getMessage()); // prints 401 Token invalid - Invalid token: Stateless token expired
access.refreshToken();
parent.accessTokenGC = access.getAccessToken(); // returns null thus I cannot proceed