इस दस्तावेज़ में बार-बार होने वाले इवेंट और उनके इंस्टेंस के साथ काम करने का तरीका बताया गया है.
बार-बार होने वाले इवेंट बनाना
बार-बार होने वाले इवेंट बनाना, event
संसाधन के recurrence
फ़ील्ड सेट के साथ, एक सामान्य (एक) इवेंट बनाने जैसा ही है.
प्रोटोकॉल
POST /calendar/v3/calendars/primary/events ... { "summary": "Appointment", "location": "Somewhere", "start": { "dateTime": "2011-06-03T10:00:00.000-07:00", "timeZone": "America/Los_Angeles" }, "end": { "dateTime": "2011-06-03T10:25:00.000-07:00", "timeZone": "America/Los_Angeles" }, "recurrence": [ "RRULE:FREQ=WEEKLY;UNTIL=20110701T170000Z", ], "attendees": [ { "email": "attendeeEmail", # Other attendee's data... }, # ... ], }
Java
Event event = new Event(); event.setSummary("Appointment"); event.setLocation("Somewhere"); ArrayList<EventAttendee> attendees = new ArrayList<EventAttendee>(); attendees.add(new EventAttendee().setEmail("attendeeEmail")); // ... event.setAttendees(attendees); DateTime start = DateTime.parseRfc3339("2011-06-03T10:00:00.000-07:00"); DateTime end = DateTime.parseRfc3339("2011-06-03T10:25:00.000-07:00"); event.setStart(new EventDateTime().setDateTime(start).setTimeZone("America/Los_Angeles")); event.setEnd(new EventDateTime().setDateTime(end).setTimeZone("America/Los_Angeles")); event.setRecurrence(Arrays.asList("RRULE:FREQ=WEEKLY;UNTIL=20110701T170000Z")); Event recurringEvent = service.events().insert("primary", event).execute(); System.out.println(createdEvent.getId());
.NET
Event event = new Event() { Summary = "Appointment", Location = "Somewhere", Start = new EventDateTime() { DateTime = new DateTime("2011-06-03T10:00:00.000:-07:00") TimeZone = "America/Los_Angeles" }, End = new EventDateTime() { DateTime = new DateTime("2011-06-03T10:25:00.000:-07:00") TimeZone = "America/Los_Angeles" }, Recurrence = new String[] { "RRULE:FREQ=WEEKLY;UNTIL=20110701T170000Z" }, Attendees = new List<EventAttendee>() { new EventAttendee() { Email: "attendeeEmail" }, // ... } }; Event recurringEvent = service.Events.Insert(event, "primary").Fetch(); Console.WriteLine(recurringEvent.Id);
Python
event = { 'summary': 'Appointment', 'location': 'Somewhere', 'start': { 'dateTime': '2011-06-03T10:00:00.000-07:00', 'timeZone': 'America/Los_Angeles' }, 'end': { 'dateTime': '2011-06-03T10:25:00.000-07:00', 'timeZone': 'America/Los_Angeles' }, 'recurrence': [ 'RRULE:FREQ=WEEKLY;UNTIL=20110701T170000Z', ], 'attendees': [ { 'email': 'attendeeEmail', # Other attendee's data... }, # ... ], } recurring_event = service.events().insert(calendarId='primary', body=event).execute() print recurring_event['id']
PHP
$event = new Google_Service_Calendar_Event(); $event->setSummary('Appointment'); $event->setLocation('Somewhere'); $start = new Google_Service_Calendar_EventDateTime(); $start->setDateTime('2011-06-03T10:00:00.000-07:00'); $start->setTimeZone('America/Los_Angeles'); $event->setStart($start); $end = new Google_Service_Calendar_EventDateTime(); $end->setDateTime('2011-06-03T10:25:00.000-07:00'); $end->setTimeZone('America/Los_Angeles'); $event->setEnd($end); $event->setRecurrence(array('RRULE:FREQ=WEEKLY;UNTIL=20110701T170000Z')); $attendee1 = new Google_Service_Calendar_EventAttendee(); $attendee1->setEmail('attendeeEmail'); // ... $attendees = array($attendee1, // ... ); $event->attendees = $attendees; $recurringEvent = $service->events->insert('primary', $event); echo $recurringEvent->getId();
Ruby
event = Google::Apis::CalendarV3::Event.new( summary: 'Appointment', location: 'Somewhere', start: { date_time: '2011-06-03T10:00:00.000-07:00', time_zone: 'America/Los_Angeles' }, end: { date_time: '2011-06-03T10:25:00.000-07:00', time_zone: 'America/Los_Angeles' }, recurrence: ['RRULE:FREQ=WEEKLY;UNTIL=20110701T170000Z'] attendees: [ { email: 'attendeeEmail' }, #... ] ) response = client.insert_event('primary', event) print response.id
ऐक्सेस के इंस्टेंस
बार-बार होने वाले किसी इवेंट के सभी इंस्टेंस देखने के लिए, events.instances() अनुरोध का इस्तेमाल किया जा सकता है.
डिफ़ॉल्ट रूप से, events.list()
अनुरोध करने पर सिर्फ़ एक इवेंट, बार-बार होने वाले इवेंट, और अपवाद दिखते हैं. हालांकि, जो मामले अपवाद नहीं हैं उनके लिए कोई वैल्यू नहीं दिखाई जाती.
अगर singleEvents
पैरामीटर
true
को सेट किया गया है, तो नतीजे में सभी अलग-अलग इंस्टेंस दिखते हैं. हालांकि, बार-बार होने वाले इवेंट नहीं दिखते. जब कोई उपयोगकर्ता जिसके पास खाली/व्यस्त होने की अनुमतियां हैं, वह events.list()
के बारे में क्वेरी करता है, तो यह ऐसे काम करता है जैसे singleEvent
true
है. ऐक्सेस कंट्रोल लिस्ट के नियमों के बारे में ज़्यादा जानकारी पाने के लिए, Acl देखें.
हर इंस्टेंस, एक इवेंट जैसे ही होते हैं. इंस्टेंस में recurrence
फ़ील्ड सेट नहीं होता, बल्कि यह बार-बार होने वाले पैरंट इवेंट से अलग होता है.
ये इवेंट फ़ील्ड, खास तौर पर इंस्टेंस के लिए हैं:
recurringEventId
— इस इंस्टेंस से जुड़े बार-बार होने वाले पैरंट इवेंट का आईडीoriginalStartTime
— यह इंस्टेंस, पैरंट बार-बार होने वाले इवेंट में बार-बार होने वाले डेटा के हिसाब से शुरू होने का समय होता है. अगर इंस्टेंस को फिर से शेड्यूल किया गया हो, तो यह असलstart
समय से अलग हो सकता है. यह बार-बार होने वाले इवेंट की सीरीज़ में इंस्टेंस की खास तौर पर पहचान करता है. भले ही, इंस्टेंस को किसी दूसरे पते पर ले जाया गया हो.
इंस्टेंस में बदलाव करना या उन्हें मिटाना
किसी सिंगल इंस्टेंस (अपवाद की वजह से) में बदलाव करने के लिए क्लाइंट ऐप्लिकेशन को सबसे पहले इंस्टेंस को वापस लाना होगा. इसके बाद, अपडेट किए गए डेटा के साथ इंस्टेंस में बदलाव करने वाले यूआरएल को अनुमति वाला PUT अनुरोध भेजकर इसे अपडेट करना होगा. यूआरएल इस तरह का होता है:
https://www.googleapis.com/calendar/v3/calendars/calendarId/events/instanceId
calendarId और instanceId की जगह सही वैल्यू का इस्तेमाल करें.
सफल होने पर, सर्वर अपडेट किए गए इंस्टेंस के साथ एचटीटीपी 200 OK स्थिति कोड दिखाता है. यहां दिए गए उदाहरण में, बार-बार होने वाले इवेंट को रद्द करने का तरीका बताया गया है.
प्रोटोकॉल
PUT /calendar/v3/calendars/primary/events/instanceId ... { "kind": "calendar#event", "id": "instanceId", "etag": "instanceEtag", "status": "cancelled", "htmlLink": "https://www.google.com/calendar/event?eid=instanceEid", "created": "2011-05-23T22:27:01.000Z", "updated": "2011-05-23T22:27:01.000Z", "summary": "Recurring event", "location": "Somewhere", "creator": { "email": "userEmail" }, "recurringEventId": "recurringEventId", "originalStartTime": "2011-06-03T10:00:00.000-07:00", "organizer": { "email": "userEmail", "displayName": "userDisplayName" }, "start": { "dateTime": "2011-06-03T10:00:00.000-07:00", "timeZone": "America/Los_Angeles" }, "end": { "dateTime": "2011-06-03T10:25:00.000-07:00", "timeZone": "America/Los_Angeles" }, "iCalUID": "eventUID", "sequence": 0, "attendees": [ { "email": "attendeeEmail", "displayName": "attendeeDisplayName", "responseStatus": "needsAction" }, # ... { "email": "userEmail", "displayName": "userDisplayName", "responseStatus": "accepted", "organizer": true, "self": true } ], "guestsCanInviteOthers": false, "guestsCanSeeOtherGuests": false, "reminders": { "useDefault": true } }
Java
// First retrieve the instances from the API. Events instances = service.events().instances("primary", "recurringEventId").execute(); // Select the instance to cancel. Event instance = instances.getItems().get(0); instance.setStatus("cancelled"); Event updatedInstance = service.events().update("primary", instance.getId(), instance).execute(); // Print the updated date. System.out.println(updatedInstance.getUpdated());
.NET
// First retrieve the instances from the API. Events instances = service.Events.Instances("primary", "recurringEventId").Fetch(); // Select the instance to cancel. Event instance = instances.Items[0]; instance.Status = "cancelled"; Event updatedInstance = service.Events.Update(instance, "primary", instance.Id).Fetch(); // Print the updated date. Console.WriteLine(updatedInstance.Updated);
Python
# First retrieve the instances from the API. instances = service.events().instances(calendarId='primary', eventId='recurringEventId').execute() # Select the instance to cancel. instance = instances['items'][0] instance['status'] = 'cancelled' updated_instance = service.events().update(calendarId='primary', eventId=instance['id'], body=instance).execute() # Print the updated date. print updated_instance['updated']
PHP
$events = $service->events->instances("primary", "eventId"); // Select the instance to cancel. $instance = $events->getItems()[0]; $instance->setStatus('cancelled'); $updatedInstance = $service->events->update('primary', $instance->getId(), $instance); // Print the updated date. echo $updatedInstance->getUpdated();
Ruby
# First retrieve the instances from the API. instances = client.list_event_instances('primary', 'recurringEventId') # Select the instance to cancel. instance = instances.items[0] instance.status = 'cancelled' response = client.update_event('primary', instance.id, instance) print response.updated
नीचे दिए गए सभी इंस्टेंस में बदलाव करें
किसी दिए गए (टारगेट) इंस्टेंस पर या उसके बाद, बार-बार होने वाले इवेंट के सभी इंस्टेंस बदलने के लिए, आपको दो अलग-अलग एपीआई अनुरोध करने होंगे. इन अनुरोधों से, बार-बार होने वाले ओरिजनल इवेंट को दो हिस्सों में बांट दिया जाता है: ओरिजनल इवेंट में बदलाव किए बिना, इवेंट को बनाए रखा जाता है और बार-बार होने वाले नए इवेंट में ऐसे इंस्टेंस होते हैं जिनमें बदलाव लागू किया गया है:- अपडेट किए जाने वाले इंस्टेंस के मूल इवेंट को छोटा करने के लिए,
events.update()
को कॉल करें. ऐसा करने के लिए,RRULE
केUNTIL
कॉम्पोनेंट को इस तरह सेट करें कि वह पहले टारगेट इंस्टेंस के शुरू होने के समय से पहले का हो. इसके अलावा,UNTIL
के बजाय,COUNT
कॉम्पोनेंट को सेट किया जा सकता है. - आपको जिस बदलाव को लागू करना है उसे छोड़कर, मूल इवेंट के डेटा के साथ बार-बार होने वाला नया इवेंट बनाने के लिए,
events.insert()
को कॉल करें. बार-बार होने वाले नए इवेंट के शुरू होने का समय टारगेट इंस्टेंस के शुरू होने का समय होना चाहिए.
इस उदाहरण में, पिछले उदाहरणों से बार-बार होने वाले इवेंट के तीसरे इंस्टेंस से शुरू करते हुए, जगह को "कहीं और" में बदलने का तरीका बताया गया है.
प्रोटोकॉल
# Updating the original recurring event to trim the instance list: PUT /calendar/v3/calendars/primary/events/recurringEventId ... { "summary": "Appointment", "location": "Somewhere", "start": { "dateTime": "2011-06-03T10:00:00.000-07:00", "timeZone": "America/Los_Angeles" }, "end": { "dateTime": "2011-06-03T10:25:00.000-07:00", "timeZone": "America/Los_Angeles" }, "recurrence": [ "RRULE:FREQ=WEEKLY;UNTIL=20110617T065959Z", ], "attendees": [ { "email": "attendeeEmail", # Other attendee's data... }, # ... ], } # Creating a new recurring event with the change applied: POST /calendar/v3/calendars/primary/events ... { "summary": "Appointment", "location": "Somewhere else", "start": { "dateTime": "2011-06-17T10:00:00.000-07:00", "timeZone": "America/Los_Angeles" }, "end": { "dateTime": "2011-06-17T10:25:00.000-07:00", "timeZone": "America/Los_Angeles" }, "recurrence": [ "RRULE:FREQ=WEEKLY;UNTIL=20110617T065959Z", ], "attendees": [ { "email": "attendeeEmail", # Other attendee's data... }, # ... ], }