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)所以,我想得到客户(类驱动器)。在获取“驱动客户端”的代码下。我认为我应该使用 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。我的逻辑是对的吗?
- 通过用户登录获取access_token、refreshToken。
- 通过 refreshToken 获取客户端(离线)。- 并获得 refreshToken2。
- 重复 2