当前位置: 首页>>代码示例>>Java>>正文


Java TokenResponse.setRefreshToken方法代码示例

本文整理汇总了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();
}
 
开发者ID:synyx,项目名称:urlaubsverwaltung,代码行数:16,代码来源:GoogleCalendarSyncProviderServiceTest.java

示例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;
}
 
开发者ID:synyx,项目名称:urlaubsverwaltung,代码行数:39,代码来源:GoogleCalendarSyncProvider.java


注:本文中的com.google.api.client.auth.oauth2.TokenResponse.setRefreshToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。