Google Groups

Re: Token refresh after: 'Getting 401 Token invalid - Invalid token: Stateless token expired' fails

Caroline McLean May 17, 2012 10:43 AM
Posted in group: Developer Forum for Google API Access using OAuth2
The refresh token is only issued once on the first request.  If you requested the token once and already issued approval the second request for a code for token exchange will not return the refresh token.  You can set the approval_prompt=force to force re-approval and hence reissue of the refresh token or you can revoke the token from the following UI, and then reissue the request.

On Wednesday, May 9, 2012 7:28:07 AM UTC-4, Yaniv Inbar wrote:
Would you kindly upgrade to 1.8.0-beta and try again?  It won't fix the problem, but it may make it slightly easier to debug.

Another thing you can try is to enable logging and look if there is anything suspicious going on:

Since it says "Stateless token expired", I suspect it is a problem with the refresh token.

Yaniv Inbar
Senior Software Engineer
Google Inc.

On Sat, May 5, 2012 at 9:03 AM, Sreenath K <> wrote:

I am facing the same problem... Did you got the solution. If you got any solution for this please help me out.


On Saturday, 21 April 2012 23:32:37 UTC+5:30, James Jones wrote:
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.set("GData-Version", "3");
try {
res = req.execute();
} catch ( ee) {
// try to refresh the token
try {
System.out.println(ee.getMessage());   // prints  401 Token invalid - Invalid token: Stateless token expired
parent.accessTokenGC = access.getAccessToken();   // returns null thus I cannot proceed

Any help greatly appreciated!