オフラインでログインするためのrefreshTokenを取得したい。アクセストークンは取得済みですが、refreshTokenが取得できません。ここに私のソースコードがあります:
public void OpenBrower(){
httpTransport = new NetHttpTransport();
jsonFactory = new JacksonFactory();
flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, jsonFactory, CLIENT_ID, CLIENT_SECRET,
Arrays.asList(DriveScopes.DRIVE)).setAccessType("online").setApprovalPrompt("auto").build();
String url = flow.newAuthorizationUrl().setRedirectUri(REDIRECT_URI).build();
try {
java.awt.Desktop.getDesktop().browse(java.net.URI.create(url));
} catch (IOException ex) {
Logger.getLogger(GoogleD.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void Register(String code){
GoogleTokenResponse response = null;
try {
response = flow.newTokenRequest(code).setRedirectUri(REDIRECT_URI).execute();
} catch (IOException ex) {
Logger.getLogger(GoogleD.class.getName()).log(Level.SEVERE, null, ex);
}
GoogleCredential credential = new GoogleCredential().setFromTokenResponse(response);
client = new Drive.Builder(httpTransport, jsonFactory, credential).build();
try {
System.out.println(credential.refreshToken());
} catch (IOException ex) {
Logger.getLogger(GoogleD.class.getName()).log(Level.SEVERE, null, ex);
}
}