Gmail कैलेंडर के साथ काम करना

कैलेंडर जोड़ना, संपादित करना और हटाना

Aspose.Email अनुप्रयोगों को Gmail कैलेंडरों को उपयोग करके प्रबंधित करने की अनुमति देता है IGmailClient जो Gmail कैलेंडरों को जोड़ने, हटाने और अपडेट करने जैसी सुविधाएँ प्रदान करता है। यह क्लाइंट क्लास ExtendedCalendar प्रकार की वस्तुओं की सूची लौटाता है जो Gmail कैलेंडर आइटम्स के बारे में जानकारी रखती हैं। IGmailClient क्लास कैलेंडरों के लिए निम्नलिखित फ़ंक्शन उजागर करता है:

क्लाइंट के सभी कैलेंडर की सूची प्राप्त करें

  • deleteCalendar इसे कैलेंडर को हटाने के लिए उपयोग किया जा सकता है
  • fetchCalendar इसे क्लाइंट के विशिष्ट कैलेंडर को लाने के लिए उपयोग किया जा सकता है
  • updateCalendar यह फ़ंक्शन क्लाइंट के संशोधित कैलेंडर को पुनः सम्मिलित करने के लिए उपयोग किया जाता है

कैलेंडर तक पहुँचने के लिए, GoogleTestUser को जीमेल खाते की प्रमाणपत्रों से आरंभ किया जाता है। GoogleOAuthHelper का उपयोग उपयोगकर्ता के लिए एक्सेस टोकन प्राप्त करने के लिए किया जाता है, जिसे आगे प्रारंभ करने के लिए उपयोग किया जाता है IGmailClient.

इंसर्ट, फ़ेच और अपडेट

कैलेंडर डालने के लिए, एक को आरंभ करें Calendar प्रकार वस्तु और इसे उपयोग करके डालें createCalendar फ़ंक्शन। createCalendar नवीनतम रूप से सम्मिलित कैलेंडर का आईडी लौटाता है। इस आईडी का उपयोग सर्वर से कैलेंडर लाने के लिए किया जा सकता है। निम्नलिखित कोड स्निपेट दर्शाता है कि कैलेंडर को कैसे सम्मिलित, प्राप्त और अपडेट किया जाए।

try (IGmailClient client = GmailClient.getInstance(accessToken, email)) {
    // Insert, get and update calendar
    Calendar calendar = new Calendar("Summary", "Description", "Location", "America/Los_Angeles");

    // Insert calendar and Retrieve same calendar using id
    String id = client.createCalendar(calendar);
    Calendar cal = client.fetchCalendar(id);

    // Change information in the fetched calendar and Update calendar
    cal.setDescription("New Description");
    cal.setLocation("New Location");
    client.updateCalendar(cal);
}

निर्दिष्ट कैलेंडर हटाएँ

एक विशिष्ट कैलेंडर को हटाने के लिए, हमें क्लाइंट के सभी कैलेंडर की सूची प्राप्त करनी होगी और फिर आवश्यकतानुसार हटाना होगा। listCalendars सूची लौटाता है ExtendedCalendar जिसमें Gmail कैलेंडर शामिल हैं। निम्नलिखित कोड स्निपेट दर्शाता है कि विशिष्ट कैलेंडर को कैसे हटाया जाए।

try (IGmailClient client = GmailClient.getInstance(accessToken, email)) {
    // Access and delete calendar with summary starting from "Calendar summary"
    String summary = "Calendar summary";

    // Get calendars list
    ExtendedCalendar[] lst = client.listCalendars();

    for (ExtendedCalendar extCal : lst) {
        // Delete selected calendars
        if (extCal.getSummary().startsWith(summary))
            client.deleteCalendar(extCal.getId());
    }
}

कैलेण्डर एक्सेस कंट्रोल के साथ काम करना

Aspose.Email कैलेंडर आइटम्स के एक्सेस कंट्रोल पर पूर्ण नियंत्रण प्रदान करता है। listAccessRules फ़ंक्शन द्वारा उजागर किया गया है IGmailClient जो सूची देता है AccessControlRule. व्यक्तिगत नियम जानकारी को पुनः प्राप्त, संशोधित और क्लाइंट के कैलेंडर के लिए वापस सहेजा जा सकता है। IGmailClient एक्सेस कंट्रोल नियमों को प्रबंधित करने के लिए निम्नलिखित फ़ंक्शन शामिल हैं।

  • listAccessRules यह फ़ंक्शन सूची प्रदान करता है AccessControlRule
  • createAccessRule यह फ़ंक्शन कैलेंडर के लिए नया एक्सेस नियम बनाता है।
  • updateAccessRule यह फ़ंक्शन एक्सेस नियम को अपडेट करने के लिए उपयोग किया जाता है।
  • fetchAccessRule इसे क्लाइंट के कैलेंडर के लिए विशिष्ट एक्सेस नियम लाने के लिए इस्तेमाल किया जा सकता है
  • deleteAccessRule यह फ़ंक्शन एक्सेस नियम को हटाने के लिए उपयोग किया जाता है।

निम्नलिखित कोड स्निपेट दर्शाता है कि एक्सेस नियमों को प्रबंधित करने के लिए फ़ंक्शन कैसे उपयोग किए जाते हैं:

try (IGmailClient client = GmailClient.getInstance(accessToken, email)) {
    // Retrieve list of calendars for the current client
    ExtendedCalendar[] calendarList = client.listCalendars();

    // Get first calendar id and retrieve list of AccessControlRule for the first calendar
    String calendarId = calendarList[0].getId();
    AccessControlRule[] roles1 = client.listAccessRules(calendarId);

    // Create a local access control rule and Set rule properties
    AccessControlRule rule = new AccessControlRule();
    rule.setRole(AccessRole.reader);
    rule.setScope(new AclScope(AclScopeType.user, email2));

    // Insert new rule for the calendar. It returns the newly created rule
    AccessControlRule createdRule = client.createAccessRule(calendarId, rule);

    // Get list of rules
    AccessControlRule[] roles2 = client.listAccessRules(calendarId);

    // Current list length should be 1 more than the earlier one
    if (roles1.length + 1 == roles2.length) {
        System.out.println("List lengths are ok");
    } else {
        System.out.println("List lengths are not ok");
        return;
    }

    // Change rule and Update the rule for the selected calendar
    createdRule.setRole(AccessRole.writer);
    AccessControlRule updatedRule = client.updateAccessRule(calendarId, createdRule);

    // Retrieve individaul rule against a calendar
    AccessControlRule fetchedRule = client.fetchAccessRule(calendarId, createdRule.getId());

    // Delete particular rule against a given calendar and Retrieve the all rules list for the same calendar
    client.deleteAccessRule(calendarId, createdRule.getId());
    AccessControlRule[] roles3 = client.listAccessRules(calendarId);

    // Check that current rules list length should be equal to the original list length before adding and deleting the rule
    if (roles1.length == roles3.length) {
        System.out.println("List lengths are same");
    } else {
        System.out.println("List lengths are not equal");
        return;
    }
}

क्लाइंट सेटिंग्स और रंग जानकारी के साथ काम करना

Aspose.Email क्लाइंट सेटिंग्स तक पहुँचने का समर्थन करता है, उपयोग करके IGmailClient.getSettings. यह नीचे दी गई सेटिंग्स की सूची लौटाता है:

  1. dateFieldOrder
  2. displayAllTimezones
  3. hideInvitations
  4. format24HourTime
  5. defaultCalendarMode
  6. defaultEventLength
  7. locale
  8. remindOnRespondedEventsOnly
  9. alternateCalendar
  10. userLocation
  11. hideWeekends
  12. showDeclinedEvents
  13. weekStart
  14. weather
  15. customCalendarMode
  16. timezoneLabel
  17. timezone
  18. useKeyboardShortcuts
  19. country

इसी तरह क्लाइंट्स के लिए रंग जानकारी को भी उपयोग करके प्राप्त किया जा सकता है IGmailClient.getColors. यह रंग जानकारी ऑब्जेक्ट फोरग्राउंड रंगों, बैकग्राउंड रंगों और अपडेट तिथि व समय की सूची लौटाता है।

क्लाइंट सेटिंग्स तक पहुँच

निम्नलिखित कोड स्निपेट दर्शाता है कि क्लाइंट सेटिंग्स तक पहुँचने के लिए फ़ंक्शन कैसे उपयोग किए जाते हैं:

try (IGmailClient client = GmailClient.getInstance(accessToken, email)) {
    // Retrieve client settings
    Dictionary<String, String> settings = client.getSettings();
    if (settings.size() < 1) {
        System.out.println("No settings are available.");
        return;
    }

    // Traverse the settings list
    for (KeyValuePair<String, String> pair : settings) {
        // Get the setting value and test if settings are ok
        String value = client.getSetting(pair.getKey());
        if (pair.getValue().equals(value)) {
            System.out.println("Key = " + pair.getKey() + ", Value = " + pair.getValue());
        } else {
            System.out.println("Settings could not be retrieved");
        }
    }
}

रंग जानकारी तक पहुँच

निम्नलिखित कोड स्निपेट दर्शाता है कि क्लाइंट रंग सेटिंग्स तक पहुँचने के लिए फ़ंक्शन कैसे उपयोग किए जाते हैं।

try (IGmailClient client = GmailClient.getInstance(accessToken, email)) {
    ColorsInfo colors = client.getColors();
    Dictionary<String, Colors> palettes = colors.getCalendar();

    // Traverse the settings list
    for (KeyValuePair<String, Colors> pair : palettes) {
        System.out.println("Key = " + pair.getKey() + ", Color = " + pair.getValue());
    }
    System.out.println("Update Date = " + colors.getUpdated());
}

अपॉइंटमेंट्स के साथ काम करना

Aspose.Email कार्य करने के लिए सुविधाएँ प्रदान करता है अपॉइंटमेंट्स Google कैलेंडरों में। निम्नलिखित कार्यों की सूची है जो Google कैलेंडर में अपॉइंटमेंट्स पर की जा सकती है:

  1. अपॉइंटमेंट जोड़ें - createAppointment, importAppointment
  2. अपॉइंटमेंट्स की सूची प्राप्त करें - listAppointments
  3. विशिष्ट अपॉइंटमेंट पुनः प्राप्त करें - fetchAppointment, listAppointmentInstances
  4. एक अपॉइंटमेंट अपडेट करें - updateAppointment
  5. एक कैलेंडर से दूसरे कैलेंडर में अपॉइंटमेंट ले जाएँ - moveAppointment
  6. अपॉइंटमेंट हटाएँ - deleteAppointment

अपॉइंटमेंट जोड़ना

निम्नलिखित कोड नमूना कैलेंडर में अपॉइंटमेंट जोड़ने की सुविधा दर्शाता है। इस नमूने में निम्नलिखित चरणों का पालन किया गया है:

  1. एक कैलेंडर बनाएं और डालें।
  2. नए कैलेंडर से अपॉइंटमेंट की सूची प्राप्त करें।
  3. एक अपॉइंटमेंट बनाएँ।
  4. अपॉइंटमेंट डालें।
try (IGmailClient client = GmailClient.getInstance(accessToken, email)) {
    // Create local calendar
    Calendar calendar1 = new Calendar("Summary", null, null, "Europe/Kiev");

    // Insert calendar and get id of inserted calendar and Get back calendar using an id
    String id = client.createCalendar(calendar1);
    Calendar cal1 = client.fetchCalendar(id);
    String calendarId1 = cal1.getId();

    try {
        // Retrieve list of appointments from the first calendar
        Appointment[] appointments = client.listAppointments(calendarId1);
        if (appointments.length > 0) {
            System.out.println("Wrong number of appointments");
            return;
        }

        // Get current time and Calculate time after an hour from now
        java.util.Calendar c = java.util.Calendar.getInstance();
        Date startDate = c.getTime();
        c.add(java.util.Calendar.HOUR_OF_DAY, 1);
        Date endDate = c.getTime();

        // Initialize a mail address collection and set attendees mail address
        MailAddressCollection attendees = new MailAddressCollection();
        attendees.add("User1.EMail@domain.com");
        attendees.add("User3.EMail@domain.com");

        // Create an appointment with above attendees
        Appointment app1 = new Appointment("Location", startDate, endDate, MailAddress.to_MailAddress(email2), attendees);

        // Set appointment summary, description, start/end time zone
        app1.setSummary("New Summary");
        app1.setDescription("New Description");
        app1.setStartTimeZone("Europe/Kiev");
        app1.setEndTimeZone("Europe/Kiev");

        // Insert appointment in the first calendar inserted above and get back inserted appointment
        Appointment app2 = client.createAppointment(calendarId1, app1);

        // Retrieve appointment using unique id
        Appointment app3 = client.fetchAppointment(calendarId1, app2.getUniqueId());
    } catch (Exception ex) {
        System.err.println(ex);
    }
    
}

अपॉइंटमेंट प्राप्त करें और अपडेट करें

यहाँ कैलेंडर को प्राप्त करने और अपडेट करने का प्रदर्शन इस प्रकार है:

  1. विशिष्ट अपॉइंटमेंट प्राप्त करें।
  2. अपॉइंटमेंट संशोधित करें।
  3. कैलेंडर में अपॉइंटमेंट अपडेट करें।

मान लिया गया है कि "calendarId" आईडी वाला कैलेंडर और "AppointmentUniqueId" विशिष्ट आईडी वाला अपॉइंटमेंट पहले ही निकाला गया है। निम्नलिखित कोड स्निपेट दर्शाता है कि कैसे अपॉइंटमेंट को प्राप्त और अपडेट किया जाए।

try (IGmailClient client = GmailClient.getInstance(accessToken, email)) {
    String calendarId = client.listCalendars()[0].getId();
    String AppointmentUniqueId = client.listAppointments(calendarId)[0].getUniqueId();

    // Retrieve Appointment
    Appointment app3 = client.fetchAppointment(calendarId, AppointmentUniqueId);
    // Change the appointment information
    app3.setSummary("New Summary");
    app3.setDescription("New Description");
    app3.setLocation("New Location");
    app3.setFlags(AppointmentFlags.AllDayEvent);
    java.util.Calendar c = java.util.Calendar.getInstance();
    c.add(java.util.Calendar.HOUR_OF_DAY, 2);
    app3.setStartDate(c.getTime());
    c.add(java.util.Calendar.HOUR_OF_DAY, 1);
    app3.setEndDate(c.getTime());
    app3.setStartTimeZone("Europe/Kiev");
    app3.setEndTimeZone("Europe/Kiev");
    // Update the appointment and get back updated appointment
    Appointment app4 = client.updateAppointment(calendarId, app3);
}

अपॉइंटमेंट को स्थानांतरित और हटाएँ

Appointment स्रोत कैलेंडर, गंतव्य कैलेंडर और स्रोत कैलेंडर में अपॉइंटमेंट के विशिष्ट आईडी प्रदान करके इसे स्थानांतरित किया जा सकता है। निम्नलिखित कोड स्निपेट दर्शाता है कि कैसे अपॉइंटमेंट को स्थानांतरित और हटाया जाए।

try (IGmailClient client = GmailClient.getInstance(accessToken, email)) {
    String SourceCalendarId = client.listCalendars()[0].getId();
    String DestinationCalendarId = client.listCalendars()[1].getId();
    String TargetAppUniqueId = client.listAppointments(SourceCalendarId)[0].getUniqueId();

    // Retrieve the list of appointments in the destination calendar before moving the appointment
    Appointment[] appointments = client.listAppointments(DestinationCalendarId);
    System.out.println("Before moving count = " + appointments.length);
    Appointment Movedapp = client.moveAppointment(SourceCalendarId, DestinationCalendarId, TargetAppUniqueId);

    // Retrieve the list of appointments in the destination calendar after moving the appointment
    appointments = client.listAppointments(DestinationCalendarId);
    System.out.println("After moving count = " + appointments.length);

    // Delete particular appointment from a calendar using unique id
    client.deleteAppointment(DestinationCalendarId, Movedapp.getUniqueId());

    // Retrieve the list of appointments. It should be one less than the earlier appointments in the destination calendar
    appointments = client.listAppointments(DestinationCalendarId);
    System.out.println("After deleting count = " + appointments.length);
}