मान लें कि कोई ऐसा ऐप्लिकेशन है जो उपयोगकर्ताओं को हाइकिंग के सबसे अच्छे रूट ढूंढने में मदद करता है. हाइकिंग प्लान को कैलेंडर इवेंट के तौर पर जोड़ने पर, उपयोगकर्ताओं को अपने-आप व्यवस्थित रहने में मदद मिलती है. Google Calendar, उन्हें प्लान शेयर करने में मदद करता है और इसके बारे में याद दिलाता है, ताकि वे बिना किसी परेशानी के तैयारी कर सकें. इसके अलावा, Google के प्रॉडक्ट के आसान इंटिग्रेशन की वजह से, Google Maps उन्हें मीटिंग की जगह पर समय से पहुंचाता है.
इस लेख में, कैलेंडर इवेंट बनाने और उन्हें अपने उपयोगकर्ताओं के कैलेंडर में जोड़ने का तरीका बताया गया है.
इवेंट जोड़ें
कोई इवेंट बनाने के लिए, events.insert तरीके का इस्तेमाल करें.
साथ ही, कम से कम ये पैरामीटर उपलब्ध कराएं:
calendarIdकैलेंडर का आइडेंटिफ़ायर है. यह उस कैलेंडर का ईमेल पता हो सकता है जिस पर इवेंट बनाना है या कोई खास कीवर्ड'primary'. यह कीवर्ड, साइन इन किए हुए उपयोगकर्ता के मुख्य कैलेंडर का इस्तेमाल करता है. अगर आपको उस कैलेंडर का ईमेल पता नहीं पता जिसका इस्तेमाल करना है, तो Calendar के वेब यूज़र इंटरफ़ेस (यूआई) में, कैलेंडर की सेटिंग में जाकर ("कैलेंडर का पता" सेक्शन में) इसे देखा जा सकता है. इसके अलावा,calendarList.listकॉल के नतीजे में भी इसे ढूंढा जा सकता है.event, वह इवेंट है जिसे बनाना है. इसमें शुरू होने और खत्म होने का समय जैसी सभी ज़रूरी जानकारी शामिल होती है. सिर्फ़ दो फ़ील्ड ज़रूरी हैं:startऔरendटाइम. इवेंट के सभी फ़ील्ड के बारे में जानने के लिए,Eventsसंसाधन का रेफ़रंस देखें.
इवेंट बनाने के लिए:
- अपना OAuth स्कोप
https://www.googleapis.com/auth/calendarपर सेट करें, ताकि आपके पास उपयोगकर्ता के कैलेंडर में बदलाव करने का ऐक्सेस हो. - पक्का करें कि पुष्टि किए गए उपयोगकर्ता के पास, आपके दिए गए
calendarIdवाले कैलेंडर में लिखने का ऐक्सेस हो. उदाहरण के लिए,calendarList.getकोcalendarIdके लिए कॉल करके औरaccessRoleकी जांच करके.
इवेंट का मेटाडेटा जोड़ना
कैलेंडर इवेंट बनाते समय, आपके पास इवेंट का मेटाडेटा जोड़ने का विकल्प होता है. अगर आपने इवेंट बनाते समय मेटाडेटा नहीं जोड़ा है, तो events.update तरीके का इस्तेमाल करके, कई फ़ील्ड अपडेट किए जा सकते हैं. हालांकि, कुछ फ़ील्ड, जैसे कि इवेंट आईडी, सिर्फ़ events.insert ऑपरेशन के दौरान सेट किए जा सकते हैं.
- जगह
- जगह के फ़ील्ड में पता जोड़ने से, "रवाना होने का समय" जैसी सुविधाएं चालू हो जाती हैं. साथ ही, दिशा-निर्देशों के साथ मैप दिखता है.
- इवेंट आईडी
- इवेंट बनाते समय, आपके पास अपना इवेंट आईडी जनरेट करने का विकल्प होता है. यह आईडी, फ़ॉर्मैट की ज़रूरी शर्तों के मुताबिक होना चाहिए. इससे, आपके स्थानीय डेटाबेस में मौजूद एंटिटी को Calendar में मौजूद इवेंट के साथ सिंक रखा जा सकता है. साथ ही, अगर Calendar के बैकएंड में ऑपरेशन के सफलतापूर्वक पूरा होने के बाद, किसी वजह से वह फ़ेल हो जाता है, तो डुप्लीकेट इवेंट नहीं बनता. अगर आपने इवेंट आईडी नहीं दिया है, तो सर्वर एक आईडी जनरेट करता है. ज़्यादा जानकारी के लिए, इवेंट आईडी रेफ़रंस देखें.
- अतिथि
- आपके बनाए गए इवेंट, शामिल किए गए सभी मेहमानों के मुख्य Calendar कैलेंडर पर, एक ही इवेंट आईडी के साथ दिखते हैं. अगर आपने अपने इंसर्ट अनुरोध में
sendUpdatesको"all"या"externalOnly"पर सेट किया है, तो शामिल किए गए मेहमानों को आपके इवेंट के लिए ईमेल से सूचना मिलती है. ज़्यादा जानने के लिए, एक से ज़्यादा मेहमानों वाले इवेंट देखें.
यहां दिए गए उदाहरणों में, इवेंट बनाने और उसका मेटाडेटा सेट करने का तरीका बताया गया है:
ऐप पर जाएं
// Refer to the Go quickstart on how to setup the environment:
// https://developers.google.com/workspace/calendar/quickstart/go
// Change the scope to calendar.CalendarScope and delete any stored credentials.
event := &calendar.Event{
Summary: "Google I/O 2015",
Location: "800 Howard St., San Francisco, CA 94103",
Description: "A chance to hear more about Google's developer products.",
Start: &calendar.EventDateTime{
DateTime: "2015-05-28T09:00:00-07:00",
TimeZone: "America/Los_Angeles",
},
End: &calendar.EventDateTime{
DateTime: "2015-05-28T17:00:00-07:00",
TimeZone: "America/Los_Angeles",
},
Recurrence: []string{"RRULE:FREQ=DAILY;COUNT=2"},
Attendees: []*calendar.EventAttendee{
&calendar.EventAttendee{Email:"lpage@example.com"},
&calendar.EventAttendee{Email:"sbrin@example.com"},
},
}
calendarId := "primary"
event, err = srv.Events.Insert(calendarId, event).Do()
if err != nil {
log.Fatalf("Unable to create event. %v\n", err)
}
fmt.Printf("Event created: %s\n", event.HtmlLink)
Java
// Refer to the Java quickstart on how to setup the environment:
// https://developers.google.com/workspace/calendar/quickstart/java
// Change the scope to CalendarScopes.CALENDAR and delete any stored
// credentials.
Event event = new Event()
.setSummary("Google I/O 2015")
.setLocation("800 Howard St., San Francisco, CA 94103")
.setDescription("A chance to hear more about Google's developer products.");
DateTime startDateTime = new DateTime("2015-05-28T09:00:00-07:00");
EventDateTime start = new EventDateTime()
.setDateTime(startDateTime)
.setTimeZone("America/Los_Angeles");
event.setStart(start);
DateTime endDateTime = new DateTime("2015-05-28T17:00:00-07:00");
EventDateTime end = new EventDateTime()
.setDateTime(endDateTime)
.setTimeZone("America/Los_Angeles");
event.setEnd(end);
String[] recurrence = new String[] {"RRULE:FREQ=DAILY;COUNT=2"};
event.setRecurrence(Arrays.asList(recurrence));
EventAttendee[] attendees = new EventAttendee[] {
new EventAttendee().setEmail("lpage@example.com"),
new EventAttendee().setEmail("sbrin@example.com"),
};
event.setAttendees(Arrays.asList(attendees));
EventReminder[] reminderOverrides = new EventReminder[] {
new EventReminder().setMethod("email").setMinutes(24 * 60),
new EventReminder().setMethod("popup").setMinutes(10),
};
Event.Reminders reminders = new Event.Reminders()
.setUseDefault(false)
.setOverrides(Arrays.asList(reminderOverrides));
event.setReminders(reminders);
String calendarId = "primary";
event = service.events().insert(calendarId, event).execute();
System.out.printf("Event created: %s\n", event.getHtmlLink());
JavaScript
// Refer to the JavaScript quickstart on how to setup the environment:
// https://developers.google.com/workspace/calendar/quickstart/js
// Change the scope to 'https://www.googleapis.com/auth/calendar' and delete any
// stored credentials.
const event = {
'summary': 'Google I/O 2015',
'location': '800 Howard St., San Francisco, CA 94103',
'description': 'A chance to hear more about Google\'s developer products.',
'start': {
'dateTime': '2015-05-28T09:00:00-07:00',
'timeZone': 'America/Los_Angeles'
},
'end': {
'dateTime': '2015-05-28T17:00:00-07:00',
'timeZone': 'America/Los_Angeles'
},
'recurrence': [
'RRULE:FREQ=DAILY;COUNT=2'
],
'attendees': [
{'email': 'lpage@example.com'},
{'email': 'sbrin@example.com'}
],
'reminders': {
'useDefault': false,
'overrides': [
{'method': 'email', 'minutes': 24 * 60},
{'method': 'popup', 'minutes': 10}
]
}
};
const request = gapi.client.calendar.events.insert({
'calendarId': 'primary',
'resource': event
});
request.execute(function(event) {
appendPre('Event created: ' + event.htmlLink);
});
Node.js
// Refer to the Node.js quickstart on how to setup the environment:
// https://developers.google.com/workspace/calendar/quickstart/node
// Change the scope to 'https://www.googleapis.com/auth/calendar' and delete any
// stored credentials.
const event = {
'summary': 'Google I/O 2015',
'location': '800 Howard St., San Francisco, CA 94103',
'description': 'A chance to hear more about Google\'s developer products.',
'start': {
'dateTime': '2015-05-28T09:00:00-07:00',
'timeZone': 'America/Los_Angeles',
},
'end': {
'dateTime': '2015-05-28T17:00:00-07:00',
'timeZone': 'America/Los_Angeles',
},
'recurrence': [
'RRULE:FREQ=DAILY;COUNT=2'
],
'attendees': [
{'email': 'lpage@example.com'},
{'email': 'sbrin@example.com'},
],
'reminders': {
'useDefault': false,
'overrides': [
{'method': 'email', 'minutes': 24 * 60},
{'method': 'popup', 'minutes': 10},
],
},
};
calendar.events.insert({
auth: auth,
calendarId: 'primary',
resource: event,
}, function(err, event) {
if (err) {
console.log('There was an error contacting the Calendar service: ' + err);
return;
}
console.log('Event created: %s', event.htmlLink);
});
PHP
$event = new Google_Service_Calendar_Event(array(
'summary' => 'Google I/O 2015',
'location' => '800 Howard St., San Francisco, CA 94103',
'description' => 'A chance to hear more about Google\'s developer products.',
'start' => array(
'dateTime' => '2015-05-28T09:00:00-07:00',
'timeZone' => 'America/Los_Angeles',
),
'end' => array(
'dateTime' => '2015-05-28T17:00:00-07:00',
'timeZone' => 'America/Los_Angeles',
),
'recurrence' => array(
'RRULE:FREQ=DAILY;COUNT=2'
),
'attendees' => array(
array('email' => 'lpage@example.com'),
array('email' => 'sbrin@example.com'),
),
'reminders' => array(
'useDefault' => FALSE,
'overrides' => array(
array('method' => 'email', 'minutes' => 24 * 60),
array('method' => 'popup', 'minutes' => 10),
),
),
));
$calendarId = 'primary';
$event = $service->events->insert($calendarId, $event);
printf('Event created: %s\n', $event->htmlLink);
Python
# Refer to the Python quickstart on how to setup the environment:
# https://developers.google.com/workspace/calendar/quickstart/python
# Change the scope to 'https://www.googleapis.com/auth/calendar' and delete any
# stored credentials.
event = {
'summary': 'Google I/O 2015',
'location': '800 Howard St., San Francisco, CA 94103',
'description': 'A chance to hear more about Google\'s developer products.',
'start': {
'dateTime': '2015-05-28T09:00:00-07:00',
'timeZone': 'America/Los_Angeles',
},
'end': {
'dateTime': '2015-05-28T17:00:00-07:00',
'timeZone': 'America/Los_Angeles',
},
'recurrence': [
'RRULE:FREQ=DAILY;COUNT=2'
],
'attendees': [
{'email': 'lpage@example.com'},
{'email': 'sbrin@example.com'},
],
'reminders': {
'useDefault': False,
'overrides': [
{'method': 'email', 'minutes': 24 * 60},
{'method': 'popup', 'minutes': 10},
],
},
}
event = service.events().insert(calendarId='primary', body=event).execute()
print 'Event created: %s' % (event.get('htmlLink'))
Ruby
event = Google::Apis::CalendarV3::Event.new(
summary: 'Google I/O 2015',
location: '800 Howard St., San Francisco, CA 94103',
description: 'A chance to hear more about Google\'s developer products.',
start: Google::Apis::CalendarV3::EventDateTime.new(
date_time: '2015-05-28T09:00:00-07:00',
time_zone: 'America/Los_Angeles'
),
end: Google::Apis::CalendarV3::EventDateTime.new(
date_time: '2015-05-28T17:00:00-07:00',
time_zone: 'America/Los_Angeles'
),
recurrence: [
'RRULE:FREQ=DAILY;COUNT=2'
],
attendees: [
Google::Apis::CalendarV3::EventAttendee.new(
email: 'lpage@example.com'
),
Google::Apis::CalendarV3::EventAttendee.new(
email: 'sbrin@example.com'
)
],
reminders: Google::Apis::CalendarV3::Event::Reminders.new(
use_default: false,
overrides: [
Google::Apis::CalendarV3::EventReminder.new(
reminder_method: 'email',
minutes: 24 * 60
),
Google::Apis::CalendarV3::EventReminder.new(
reminder_method: 'popup',
minutes: 10
)
]
)
)
result = client.insert_event('primary', event)
puts "Event created: #{result.html_link}"
इवेंट में Drive के अटैचमेंट जोड़ना
Google Calendar के इवेंट में, Google Drive
की फ़ाइलें अटैच की जा सकती हैं. जैसे, Google Docs में मीटिंग के नोट, Google Sheets में बजट, Google Slides में प्रज़ेंटेशन या Drive की कोई अन्य काम की फ़ाइल. अटैचमेंट तब जोड़ा जा सकता है, जब आप
events.insert की मदद से कोई इवेंट बनाते हैं या बाद में अपडेट के तौर पर भी अटैचमेंट जोड़ा जा सकता है. जैसे,
events.patch की मदद से.
किसी इवेंट में Drive की फ़ाइल अटैच करने के दो तरीके हैं:
- Google Drive API के फ़ाइल संसाधन से, फ़ाइल का
alternateLinkयूआरएल,title, औरmimeTypeपाएं. आम तौर पर, इसके लिएfiles.getतरीके का इस्तेमाल किया जाता है. - अनुरोध के मुख्य हिस्से में सेट किए गए
attachmentsफ़ील्ड औरsupportsAttachmentsपैरामीटर कोtrueपर सेट करके, कोई इवेंट बनाएं या अपडेट करें.
यहां दिए गए कोड के उदाहरण में, किसी मौजूदा इवेंट को अपडेट करके उसमें अटैचमेंट जोड़ने का तरीका बताया गया है:
Java
public static void addAttachment(Calendar calendarService, Drive driveService, String calendarId,
String eventId, String fileId) throws IOException {
File file = driveService.files().get(fileId).execute();
Event event = calendarService.events().get(calendarId, eventId).execute();
List<EventAttachment> attachments = event.getAttachments();
if (attachments == null) {
attachments = new ArrayList<EventAttachment>();
}
attachments.add(new EventAttachment()
.setFileUrl(file.getAlternateLink())
.setMimeType(file.getMimeType())
.setTitle(file.getTitle()));
Event changes = new Event()
.setAttachments(attachments);
calendarService.events().patch(calendarId, eventId, changes)
.setSupportsAttachments(true)
.execute();
}
PHP
function addAttachment($calendarService, $driveService, $calendarId, $eventId, $fileId) {
$file = $driveService->files->get($fileId);
$event = $calendarService->events->get($calendarId, $eventId);
$attachments = $event->attachments;
$attachments[] = array(
'fileUrl' => $file->alternateLink,
'mimeType' => $file->mimeType,
'title' => $file->title
);
$changes = new Google_Service_Calendar_Event(array(
'attachments' => $attachments
));
$calendarService->events->patch($calendarId, $eventId, $changes, array(
'supportsAttachments' => TRUE
));
}
Python
def add_attachment(calendarService, driveService, calendarId, eventId, fileId):
file = driveService.files().get(fileId=fileId).execute()
event = calendarService.events().get(calendarId=calendarId,
eventId=eventId).execute()
attachments = event.get('attachments', [])
attachments.append({
'fileUrl': file['alternateLink'],
'mimeType': file['mimeType'],
'title': file['title']
})
changes = {
'attachments': attachments
}
calendarService.events().patch(calendarId=calendarId, eventId=eventId,
body=changes,
supportsAttachments=True).execute()
इवेंट में वीडियो और फ़ोन कॉन्फ़्रेंस जोड़ना
इवेंट को Google Meet कॉन्फ़्रेंस से जोड़ा जा सकता है, ताकि आपके उपयोगकर्ता फ़ोन कॉल या वीडियो कॉल के ज़रिए, दूर से मीटिंग कर सकें.
conferenceData
फ़ील्ड की मदद से, मौजूदा कॉन्फ़्रेंस की जानकारी पढ़ी, कॉपी, और मिटाई जा सकती है. इसके अलावा, नई कॉन्फ़्रेंस जनरेट करने का अनुरोध भी किया जा सकता है.
कॉन्फ़्रेंस की जानकारी बनाने और उसमें बदलाव करने की अनुमति देने के लिए, conferenceDataVersion अनुरोध पैरामीटर को 1 पर सेट करें.
यहां दिए गए कॉन्फ़्रेंस टाइप इस्तेमाल किए जा सकते हैं. इनकी जानकारी, conferenceData.conferenceSolution.key.type में दी गई है:
- Google Meet (
hangoutsMeet)
`calendars` और `calendarList` कलेक्शन में मौजूद `conferenceProperties.allowedConferenceSolutionTypes` को देखकर, यह जाना जा सकता है कि किसी उपयोगकर्ता के किसी भी कैलेंडर के लिए, किस तरह की कॉन्फ़्रेंस की सुविधा उपलब्ध है.
type के अलावा, conferenceSolution में name और iconUri फ़ील्ड भी होते हैं. इनका इस्तेमाल, कॉन्फ़्रेंस की सुविधा को दिखाने के लिए किया जा सकता है. जैसे, यहां दिखाया गया है:
JavaScript
const solution = event.conferenceData.conferenceSolution;
const content = document.getElementById("content");
const text = document.createTextNode("Join " + solution.name);
const icon = document.createElement("img");
icon.src = solution.iconUri;
content.appendChild(icon);
content.appendChild(text);
किसी इवेंट के लिए नई कॉन्फ़्रेंस बनाई जा सकती है. इसके लिए, रैंडम स्ट्रिंग के तौर पर, नए जनरेट किए गए requestId के साथ createRequest उपलब्ध कराएं. कॉन्फ़्रेंस एसिंक्रोनस तरीके से बनाई जाती हैं. हालांकि, अपने अनुरोध की स्थिति कभी भी देखी जा सकती है, ताकि आपके उपयोगकर्ताओं को पता चल सके कि क्या हो रहा है.
उदाहरण के लिए, किसी मौजूदा इवेंट के लिए कॉन्फ़्रेंस जनरेट करने का अनुरोध करने के लिए:
JavaScript
const eventPatch = {
conferenceData: {
createRequest: {requestId: "7qxalsvy0e"}
}
};
gapi.client.calendar.events.patch({
calendarId: "primary",
eventId: "7cbh8rpc10lrc0ckih9tafss99",
resource: eventPatch,
sendUpdates: "all",
conferenceDataVersion: 1
}).execute(function(event) {
console.log("Conference created for event: %s", event.htmlLink);
});
हो सकता है कि इस कॉल के तुरंत बाद मिलने वाले जवाब में, पूरी तरह से भरा गया
conferenceData न हो. साथ ही, स्टेटस
फ़ील्ड में pending दिखे. कॉन्फ़्रेंस की जानकारी भरने के बाद, स्टेटस कोड success में बदल जाता है. entryPoints फ़ील्ड में, इस बारे में जानकारी होती है कि आपके उपयोगकर्ताओं के लिए, कौनसे वीडियो और फ़ोन यूआरआई उपलब्ध हैं, ताकि वे कॉल कर सकें.
अगर आपको एक ही कॉन्फ़्रेंस की जानकारी के साथ, Calendar के कई इवेंट शेड्यूल करने हैं, तो एक इवेंट से दूसरे इवेंट में पूरा conferenceData कॉपी किया जा सकता है.
कुछ स्थितियों में कॉपी करना काम का होता है. उदाहरण के लिए, मान लें कि आप भर्ती करने वाला कोई ऐप्लिकेशन बना रहे हैं. इसमें उम्मीदवार और इंटरव्यू लेने वाले व्यक्ति के लिए अलग-अलग इवेंट सेट अप किए जाते हैं. आपको इंटरव्यू लेने वाले व्यक्ति की पहचान को सुरक्षित रखना है. साथ ही, आपको यह भी पक्का करना है कि सभी लोग एक ही कॉन्फ़्रेंस कॉल में शामिल हों.