0

I want to get refreshToken for login off-line. I already get access token, but I didn't get refreshToken. here is my source code :

     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);
        }        
    }
pinoyyid
  • 21,499
  • 14
  • 64
  • 115
Jaemin Lee
  • 19
  • 4

1 Answers1

2

In your code, change

.setAccessType("online")

to

.setAccessType("offline")
pinoyyid
  • 21,499
  • 14
  • 64
  • 115
  • Thank u..You have helped me many times... I have some question. so.. I will ask, I want you interest my question. – Jaemin Lee Nov 09 '13 at 15:30
  • Can you check this question?... http://stackoverflow.com/questions/19877831/how-do-i-get-refreshtoken-by-using-old-refreshtoken – Jaemin Lee Nov 09 '13 at 15:53
  • Sorry - I don't know. I don't like to use Oauth libraries so I use the raw http requests as I find them easier to debug, and not much more difficult to implement. – pinoyyid Nov 09 '13 at 16:01