इस दस्तावेज़ में, बार-बार होने वाले इवेंट और उनके इंस्टेंस के साथ काम करने का तरीका बताया गया है.
बार-बार होने वाले इवेंट बनाना
बार-बार होने वाले इवेंट बनाना, इवेंट रिसॉर्स के क्रिएट
किए गए सामान्य (एक बार होने वाले) इवेंट जैसा ही है, जिसमें इवेंट
रिसॉर्स के 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 के बारे में क्वेरी करता है जिसके पास, उपलब्धता की जानकारी देखने की अनुमति होती है, तो यह ऐसे काम करता है जैसे singleEvents को 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", ], "attendees": [ { "email": "attendeeEmail", # Other attendee's data... }, # ... ], }