本文整理汇总了Java中com.google.api.client.auth.oauth2.TokenResponse.setRefreshToken方法的典型用法代码示例。如果您正苦于以下问题:Java TokenResponse.setRefreshToken方法的具体用法?Java TokenResponse.setRefreshToken怎么用?Java TokenResponse.setRefreshToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.client.auth.oauth2.TokenResponse
的用法示例。
在下文中一共展示了TokenResponse.setRefreshToken方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCalendarEventCount
import com.google.api.client.auth.oauth2.TokenResponse; //导入方法依赖的package包/类
private Integer getCalendarEventCount() throws GeneralSecurityException, IOException {
NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
TokenResponse tokenResponse = new TokenResponse();
tokenResponse.setRefreshToken(REFRESH_TOKEN);
Credential credential = createCredentialWithRefreshToken(httpTransport, jsonFactory, tokenResponse);
Calendar calendar = new com.google.api.services.calendar.Calendar.Builder(
httpTransport, jsonFactory, credential).setApplicationName(APPLICATION_NAME).build();
Calendar.Events.List events = calendar.events().list(CALENDAR_ID);
return events.execute().getItems().size();
}
示例2: getOrCreateGoogleCalendarClient
import com.google.api.client.auth.oauth2.TokenResponse; //导入方法依赖的package包/类
/**
* Build and return an authorized google calendar client.
*
* @return an authorized calendar client service
*/
private com.google.api.services.calendar.Calendar getOrCreateGoogleCalendarClient() {
String refreshToken =
settingsService.getSettings().getCalendarSettings().getGoogleCalendarSettings().getRefreshToken();
if (googleCalendarClient != null &&
refreshToken != null &&
refreshTokenHashCode == refreshToken.hashCode()) {
LOG.debug("use cached googleCalendarClient");
return googleCalendarClient;
}
try {
LOG.info("create new googleCalendarClient");
if (refreshToken != null) {
refreshTokenHashCode = refreshToken.hashCode();
}
NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
TokenResponse tokenResponse = new TokenResponse();
tokenResponse.setRefreshToken(refreshToken);
Credential credential = createCredentialWithRefreshToken(httpTransport, JSON_FACTORY, tokenResponse);
return new com.google.api.services.calendar.Calendar.Builder(
httpTransport, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();
} catch (GeneralSecurityException | IOException e) {
LOG.error(e);
}
return null;
}