本文整理汇总了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");
}
示例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");
}
示例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();
}
示例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");
}
示例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);
}
}
示例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);
}
}
示例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();
}
}
示例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;
}
示例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);
}
}
示例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();
}