如何使用old-refreshToken获取refreshToken?

时间:2013-11-09 15:48:31

标签: java google-drive-api

1)我成功通过代码获取了refreshToken:

    public void Register(String code){
        GoogleTokenResponse response = null;
        response = flow.newTokenRequest(code).setRedirectUri(REDIRECT_URI).execute();
        refreshToken = response.getRefreshToken();                

        GoogleCredential credential = new GoogleCredential().setAccessToken(response.getAccessToken());        

        client = new Drive.Builder(httpTransport, jsonFactory, credential).build();            
    }

现在我得到了refreshToken,它被用于2)。

2)所以,我想得到客户端(类Drive)。 在获取'Drive client'的代码下。我认为我应该使用GoogleRefreshTokenRequest类来通过refreshToken获取客户端。真的吗?我确实犯过错误?

    public Drive GetClient(String refresh){
            httpTransport = new NetHttpTransport();
            jsonFactory = new JacksonFactory();
            GoogleTokenResponse response = null;
            GoogleRefreshTokenRequest req = new GoogleRefreshTokenRequest(httpTransport, 
jsonFactory, refresh, CLIENT_ID, CLIENT_SECRET);
            req.setGrantType("refresh_token");
            try {
                response = req.execute();
                System.out.println("RF token = " + response.getRefreshToken());
            } 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();             

            return client;
        }

3)而且,我想通过refreshToken获取refreshToken。我的逻辑是对的吗?

  1. 通过用户登录获取access_token,refreshToken。
  2. 通过refreshToken获取客户端(离线)。 - 并获得refreshToken2。
  3. 重复2

0 个答案:

没有答案