I'm developing an app that accesses Google APIs (starting with Calendar API) using OAuth2 and the google client libraries for that (is on Appengine and GWT BTW).
I have implemented my OAuth2Call
back servlet, extending the Google AbstractAppEngineAuthorizationCodeCallbackServlet
.
I have it working, I get access and can look at calendars etc, but have two problems:
1) I do not get a refresh token, despite explicitly requesting offline access:
public static GoogleAuthorizationCodeFlow newFlow( String scope ) throws IOException {
GoogleAuthorizationCodeFlow.Builder builder = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT,
JSON_FACTORY,
getClientSecrets(),
Collections.singleton( scope ) );
builder.setCredentialStore( new AppEngineCredentialStore() ).setAccessType("offline");
return builder.build();
}
2) I cannot see how to set the automatic refresh functionality.
These pages describe the methods:
But I can't see where to add the refresh listener. There is no such method in the GoogleAuthorizationCodeFlow.Builder
class, unlike the Credential.Builder
class
EDIT
After debugging the code more, when the credential comes back (in the onSuccess()
method) it seems to have a RefreshListener
set already.....so maybe that's their by default, and my only problem is I'm not getting a refresh_token
, despite asking for it.
Maybe need to review settings in the Google API Console also?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…