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


Java CalendarScopes类代码示例

本文整理汇总了Java中com.google.api.services.calendar.CalendarScopes的典型用法代码示例。如果您正苦于以下问题:Java CalendarScopes类的具体用法?Java CalendarScopes怎么用?Java CalendarScopes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CalendarScopes类属于com.google.api.services.calendar包,在下文中一共展示了CalendarScopes类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: authorize

import com.google.api.services.calendar.CalendarScopes; //导入依赖的package包/类
/**
 * Authorizes the installed application to access user's protected data.
 */
private static Credential authorize() throws Exception {
    // load client secrets
    final GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
            new InputStreamReader(GoogleCalendarSync.class.getResourceAsStream("/client_secrets.json")));
    if (clientSecrets.getDetails().getClientId().startsWith("Enter")
            || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
        if (logger.isErrorEnabled()) {
            logger.error("Enter Client ID and Secret from https://code.google.com/apis/console/?api=calendar "
                    + "into calendar-cmdline-sample/src/main/resources/client_secrets.json");
        }
        return null;
    }
    // set up authorization code flow
    final GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY,
            clientSecrets, Collections.singleton(CalendarScopes.CALENDAR)).setDataStoreFactory(dataStoreFactory)
            .build();
    // authorize
    return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver())
            .authorize("557837674207-61uehop5b0u5enflhc7ata9a75sf731e.apps.googleusercontent.com");
}
 
开发者ID:DrBookings,项目名称:drbookings,代码行数:24,代码来源:GoogleCalendarSync.java

示例2: authorize

import com.google.api.services.calendar.CalendarScopes; //导入依赖的package包/类
/** Authorizes the installed application to access user's protected data. */
private static Credential authorize() throws Exception {
	// load client secrets
	final GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
			new InputStreamReader(RunnableImportGoogleCalendar.class.getResourceAsStream("/client_secrets.json")));
	if (clientSecrets.getDetails().getClientId().startsWith("Enter")
			|| clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
		System.out.println("Enter Client ID and Secret from https://code.google.com/apis/console/?api=calendar "
				+ "into calendar-cmdline-sample/src/main/resources/client_secrets.json");
		System.exit(1);
	}
	// set up authorization code flow
	final GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY,
			clientSecrets, Collections.singleton(CalendarScopes.CALENDAR)).setDataStoreFactory(dataStoreFactory)
					.build();
	// authorize
	return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}
 
开发者ID:DrBookings,项目名称:drbookings,代码行数:19,代码来源:RunnableImportGoogleCalendar.java

示例3: authorize

import com.google.api.services.calendar.CalendarScopes; //导入依赖的package包/类
private String authorize(String redirectUri) {
    AuthorizationCodeRequestUrl authorizationUrl;

    Details web = new Details();
    GoogleCalendarSettings googleCalendarSettings =
            settingsService.getSettings().getCalendarSettings().getGoogleCalendarSettings();

    web.setClientId(googleCalendarSettings.getClientId());
    web.setClientSecret(googleCalendarSettings.getClientSecret());

    GoogleClientSecrets clientSecrets = new GoogleClientSecrets();

    clientSecrets.setWeb(web);

    flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets,
            Collections.singleton(CalendarScopes.CALENDAR))
            .setApprovalPrompt("force")
            .setAccessType("offline")
            .build();

    authorizationUrl = flow.newAuthorizationUrl().setRedirectUri(redirectUri);


    LOG.info("using authorizationUrl " + authorizationUrl);
    return authorizationUrl.build();
}
 
开发者ID:synyx,项目名称:urlaubsverwaltung,代码行数:27,代码来源:GoogleCalendarOAuthHandshakeController.java

示例4: authorize

import com.google.api.services.calendar.CalendarScopes; //导入依赖的package包/类
/** Authorizes the installed application to access user's protected data. */
private static Credential authorize() throws Exception {
  // load client secrets
  GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
      new InputStreamReader(CalendarSample.class.getResourceAsStream("/client_secrets.json")));
  if (clientSecrets.getDetails().getClientId().startsWith("Enter") ||
      clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
    System.out.println(
        "Overwrite the src/main/resources/client_secrets.json file with the client secrets file "
        + "you downloaded from the Quickstart tool or manually enter your Client ID and Secret "
        + "from https://code.google.com/apis/console/?api=calendar#project:380094479037 "
        + "into src/main/resources/client_secrets.json");
    System.exit(1);
  }

  // Set up authorization code flow.
  // Ask for only the permissions you need. Asking for more permissions will
  // reduce the number of users who finish the process for giving you access
  // to their accounts. It will also increase the amount of effort you will
  // have to spend explaining to users what you are doing with their data.
  // Here we are listing all of the available scopes. You should remove scopes
  // that you are not actually using.
  Set<String> scopes = new HashSet<String>();
  scopes.add(CalendarScopes.CALENDAR);
  scopes.add(CalendarScopes.CALENDAR_READONLY);

  GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
      httpTransport, JSON_FACTORY, clientSecrets, scopes)
      .setDataStoreFactory(dataStoreFactory)
      .build();
  // authorize
  return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}
 
开发者ID:tobegit3hub,项目名称:google_calendar_api_demo,代码行数:34,代码来源:CalendarSample.java

示例5: main

import com.google.api.services.calendar.CalendarScopes; //导入依赖的package包/类
public static void main(String[] args) {
  try {
    List<String> scopes = Lists.newArrayList(CalendarScopes.CALENDAR_READONLY);
    client = Utils.createCalendarClient(scopes);
    eventDataStore = Utils.getDataStoreFactory().getDataStore("EventStore");
    syncSettingsDataStore = Utils.getDataStoreFactory().getDataStore("SyncSettings");
    run();
  } catch (Throwable t) {
    t.printStackTrace();
    System.exit(1);
  }
}
 
开发者ID:googlesamples,项目名称:calendar-sync,代码行数:13,代码来源:SyncTokenSample.java

示例6: main

import com.google.api.services.calendar.CalendarScopes; //导入依赖的package包/类
public static void main(String[] args) {
  try {
    List<String> scopes = Lists.newArrayList(CalendarScopes.CALENDAR);
    client = Utils.createCalendarClient(scopes);
    run();
  } catch (Throwable t) {
    t.printStackTrace();
    System.exit(1);
  }
}
 
开发者ID:googlesamples,项目名称:calendar-sync,代码行数:11,代码来源:ConditionalModificationSample.java

示例7: authorize

import com.google.api.services.calendar.CalendarScopes; //导入依赖的package包/类
private Credential authorize(HttpTransport httpTransport, JsonFactory jsonFactory, FileDataStoreFactory dataStoreFactory) throws IOException {
    
    NDC.push("authorize");
    Marker m = new Marker("authorize");
    
    try {
        
        InputStream in = getClass().getResourceAsStream(CLIENT_SECRETS);
        
        if (in == null) {
            throw new IOException("null stream trying to open " + CLIENT_SECRETS);
        }

        GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(jsonFactory, new InputStreamReader(in));

        GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
                httpTransport,
                jsonFactory,
                clientSecrets,
                Collections.singleton(CalendarScopes.CALENDAR)).setDataStoreFactory(dataStoreFactory).build();

        return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");

    } finally {
        
        m.close();
        NDC.pop();
    }
}
 
开发者ID:home-climate-control,项目名称:dz,代码行数:30,代码来源:GCalScheduleUpdater.java

示例8: getGoogleCalendarService

import com.google.api.services.calendar.CalendarScopes; //导入依赖的package包/类
/**
 * Liefert den Zugriff auf den Google-Kalender
 *
 * @return the service
 */
public com.google.api.services.calendar.Calendar getGoogleCalendarService() {

	if (calendarService == null) {
		if (!StringUtils.isBlank(getProxyHost()) && !StringUtils.isBlank(getProxyPort())) {
			System.setProperty("http.proxyHost", getProxyHost()); //$NON-NLS-1$
			System.setProperty("http.proxyPort", getProxyPort()); //$NON-NLS-1$
			System.setProperty("https.proxyHost", getProxyHost()); //$NON-NLS-1$
			System.setProperty("https.proxyPort", getProxyPort()); //$NON-NLS-1$
		}

		try {
			final HttpTransport httpTransport = new NetHttpTransport();
			final JacksonFactory jsonFactory = new JacksonFactory();

			final List<String> scopes = Arrays.asList(CalendarScopes.CALENDAR);
			final GoogleOAuth2DAO googleOAuth2DAO = new GoogleOAuth2DAO(httpTransport, jsonFactory, getVerificationCodeReceiver(),
					fileAccessor.getFile(Constants.FILENAME_USER_SECRETS));
			final Credential credential = googleOAuth2DAO.authorize(scopes, getGoogleAccountName());

			calendarService = new com.google.api.services.calendar.Calendar.Builder(httpTransport, jsonFactory, credential)//
					.setApplicationName(Constants.APPLICATION_NAME)//
					.build();
		} catch (final IOException e) {
			throw new RuntimeException(e);
		}
	}
	return calendarService;
}
 
开发者ID:fjakop,项目名称:ngcalsync,代码行数:34,代码来源:Settings.java

示例9: requestCode

import com.google.api.services.calendar.CalendarScopes; //导入依赖的package包/类
public void requestCode(MessageReceivedEvent event, GuildSettings settings) {
	try {
		String body = "client_id=" + clientData.getClientId() + "&scope=" + CalendarScopes.CALENDAR;

		com.mashape.unirest.http.HttpResponse<JsonNode> response = Unirest.post("https://accounts.google.com/o/oauth2/device/code").header("Content-Type", "application/x-www-form-urlencoded").body(body).asJson();

		if (response.getStatus() == HttpStatusCodes.STATUS_CODE_OK) {
			Type type = new TypeToken<CodeResponse>() {
			}.getType();
			CodeResponse cr = new Gson().fromJson(response.getBody().toString(), type);

			//Send DM to user with code.
			EmbedBuilder em = new EmbedBuilder();
			em.withAuthorIcon(Main.client.getGuildByID(266063520112574464L).getIconURL());
			em.withAuthorName("DisCal");
			em.withTitle(MessageManager.getMessage("Embed.AddCalendar.Code.Title", settings));
			em.appendField(MessageManager.getMessage("Embed.AddCalendar.Code.Code", settings), cr.user_code, true);
			em.withFooterText(MessageManager.getMessage("Embed.AddCalendar.Code.Footer", settings));

			em.withUrl(cr.verification_url);
			em.withColor(36, 153, 153);

			IUser user = event.getAuthor();
			Message.sendDirectMessage(MessageManager.getMessage("AddCalendar.Auth.Code.Request.Success", settings), em.build(), user);

			//Start timer to poll Google Cal for auth
			Poll poll = new Poll(user, event.getGuild());

			poll.setDevice_code(cr.device_code);
			poll.setRemainingSeconds(cr.expires_in);
			poll.setExpires_in(cr.expires_in);
			poll.setInterval(cr.interval);
			pollForAuth(poll);
		} else {
			Message.sendDirectMessage(MessageManager.getMessage("AddCalendar.Auth.Code.Request.Failure.NotOkay", settings), event.getAuthor());

			ExceptionHandler.sendDebug(event.getAuthor(), "Error requesting access token.", "Status code: " + response.getStatus() + " | " + response.getStatusText() + " | " + response.getBody().toString(), this.getClass());
		}
	} catch (Exception e) {
		//Failed, report issue to dev.
		ExceptionHandler.sendException(event.getAuthor(), "Failed to request Google Access Code", e, this.getClass());
		IUser u = event.getAuthor();
		Message.sendDirectMessage(MessageManager.getMessage("AddCalendar.Auth.Code.Request.Failure.Unknown", settings), u);
	}
}
 
开发者ID:NovaFox161,项目名称:DisCal-Discord-Bot,代码行数:46,代码来源:Authorization.java

示例10: getCalendarServiceDomainWide

import com.google.api.services.calendar.CalendarScopes; //导入依赖的package包/类
public static Calendar getCalendarServiceDomainWide() throws GeneralSecurityException, IOException {
	return new Calendar.Builder(GoogleServices.getInstance().httpTransport, GoogleServices.getInstance().jsonFactory, null)
		.setHttpRequestInitializer(GoogleServices.getCredentialDomainWide(Arrays.asList(CalendarScopes.CALENDAR)))
		.setApplicationName(Config.get(Config.APPLICATION_NAME))
		.build();
}
 
开发者ID:andryfailli,项目名称:teampot,代码行数:7,代码来源:GoogleServices.java


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