इवेंट बनाएं

सोचिए कि एक ऐसा ऐप्लिकेशन है जो हाइकिंग के सबसे अच्छे रास्ते ढूंढने में उपयोगकर्ताओं की मदद करता है. हाइकिंग प्लान को कैलेंडर इवेंट के तौर पर जोड़ने से, उपयोगकर्ताओं को अपने-आप व्यवस्थित रहने में काफ़ी मदद मिलती है. Google कैलेंडर उन्हें प्लान शेयर करने में मदद करता है और उन्हें इसके बारे में याद दिलाता है, ताकि वे तनाव के बिना तैयारी कर सकें. साथ ही, Google प्रॉडक्ट के आसान इंटिग्रेशन की वजह से, Google Now उन्हें निकलने का समय बताता है और Google Maps उन्हें सही समय पर मीटिंग की जगह पर भेज देता है.

इस लेख में कैलेंडर इवेंट बनाने और उन्हें उपयोगकर्ताओं के कैलेंडर में जोड़ने का तरीका बताया गया है.

कोई इवेंट जोड़ें

इवेंट बनाने के लिए, कम से कम ये पैरामीटर उपलब्ध कराने वाले events.insert() तरीके को कॉल करें:

  • calendarId, कैलेंडर आइडेंटिफ़ायर होता है. यह उस कैलेंडर का ईमेल पता हो सकता है जिस पर इवेंट बनाना है. इसके अलावा, इसमें खास कीवर्ड'primary' भी हो सकता है जो लॉग इन किए हुए उपयोगकर्ता के मुख्य कैलेंडर का इस्तेमाल करेगा. अगर आपको जिस कैलेंडर का इस्तेमाल करना है उसका ईमेल पता नहीं है, तो उसे Google Calendar के वेब यूज़र इंटरफ़ेस (यूआई) की कैलेंडर सेटिंग ("कैलेंडर पता" सेक्शन में) में देखा जा सकता है या उसे calendarList.list() कॉल के नतीजे में ढूंढा जा सकता है.
  • event एक ऐसा इवेंट है जिसे सभी ज़रूरी जानकारी के साथ बनाया जाना है. जैसे, शुरू और खत्म होना. सिर्फ़ दो ज़रूरी फ़ील्ड हैं, start और end बार. इवेंट फ़ील्ड के पूरे सेट के लिए event रेफ़रंस देखें.

इवेंट बनाने के लिए:

  • अपने OAuth स्कोप को https://www.googleapis.com/auth/calendar पर सेट करें, ताकि आपके पास उपयोगकर्ता के कैलेंडर में बदलाव करने का ऐक्सेस हो.
  • पक्का करें कि पुष्टि किए गए उपयोगकर्ता के पास, आपके दिए गए calendarId से कैलेंडर में लिखने का ऐक्सेस हो. उदाहरण के लिए, calendarId के लिए calendarList.get() को कॉल करना और accessRole देखना.

इवेंट का मेटाडेटा जोड़ना

कैलेंडर इवेंट बनाते समय, आपके पास इवेंट मेटाडेटा जोड़ने का विकल्प होता है. अगर मेटाडेटा बनाने के दौरान मेटाडेटा नहीं जोड़ने का विकल्प चुना जाता है, तो events.update() का इस्तेमाल करके कई फ़ील्ड अपडेट किए जा सकते हैं. हालांकि, इवेंट आईडी जैसे कुछ फ़ील्ड सिर्फ़ events.insert() कार्रवाई के दौरान ही सेट किए जा सकते हैं.

जगह

स्थान फ़ील्ड में कोई पता जोड़ने से ये सुविधाएं सक्षम हो जाती हैं

"निकलने का समय" या निर्देशों के साथ मैप दिखाना.

इवेंट आईडी

इवेंट बनाते समय, आपके पास अपना इवेंट आईडी जनरेट करने का विकल्प होता है

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

अतिथि

आप जो इवेंट बनाते हैं वह Google Calendar के सभी मुख्य कैलेंडर पर दिखता है

शामिल किए गए सभी मेहमानों के लिए एक ही इवेंट आईडी का इस्तेमाल किया जाएगा. अगर आपने शामिल करने के अनुरोध पर sendNotifications को true पर सेट किया है, तो मीटिंग में शामिल लोगों को भी आपके इवेंट की सूचना ईमेल से मिलेगी. ज़्यादा जानकारी के लिए, एक से ज़्यादा मेहमानों वाले इवेंट की गाइड देखें.

यहां दिए गए उदाहरणों में इवेंट बनाने और उसका मेटाडेटा सेट करने के बारे में बताया गया है:

शुरू करें

// Refer to the Go quickstart on how to setup the environment:
// https://developers.google.com/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/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/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/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/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 Drive की फ़ाइलें अटैच करने का विकल्प होता है. जैसे, Docs में मीटिंग के नोट, Sheets में बजट, Slides में प्रज़ेंटेशन या Google Drive की अन्य फ़ाइलों को. events.insert() या उसके बाद के वर्शन के साथ कोई इवेंट बनाते समय, इस अटैचमेंट को अपडेट किया जा सकता है. जैसे, events.patch()

Google Drive की किसी फ़ाइल को किसी इवेंट से अटैच करने के दो हिस्से होते हैं:

  1. Drive API फ़ाइलें संसाधन से alternateLink यूआरएल, title, और mimeType फ़ाइल पाएं. आम तौर पर, ऐसा files.get() तरीके से किया जाता है.
  2. अनुरोध के मुख्य हिस्से में सेट किए गए attachments फ़ील्ड और true पर सेट किए गए supportsAttachments पैरामीटर का इस्तेमाल करके, कोई इवेंट बनाएं या अपडेट करें.

इस कोड के उदाहरण में, अटैचमेंट जोड़ने के लिए किसी मौजूदा इवेंट को अपडेट करने का तरीका बताया गया है:

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()

इवेंट में वीडियो और फ़ोन कॉन्फ़्रेंस जोड़ें

Hangouts और Google Meet कॉन्फ़्रेंस में इवेंट जोड़े जा सकते हैं. इससे उपयोगकर्ताओं को फ़ोन कॉल या वीडियो कॉल से मीटिंग में शामिल होने में मदद मिलेगी.

conferenceData फ़ील्ड का इस्तेमाल, कॉन्फ़्रेंस की मौजूदा जानकारी को पढ़ने, कॉपी करने, और मिटाने के लिए किया जा सकता है. इसका इस्तेमाल नई कॉन्फ़्रेंस बनाने का अनुरोध करने के लिए भी किया जा सकता है. कॉन्फ़्रेंस की जानकारी बनाने और उसमें बदलाव करने की अनुमति देने के लिए, conferenceDataVersion अनुरोध पैरामीटर को 1 पर सेट करें.

फ़िलहाल, तीन तरह के conferenceData काम करते हैं. इसके बारे में conferenceData.conferenceSolution.key.type में बताया गया है:

  1. उपभोक्ताओं के लिए Hangouts (eventHangout)
  2. Hangouts का क्लासिक वर्शन Google Workspace उपयोगकर्ताओं के लिए (अब सेवा में नहीं है; eventNamedHangout)
  3. Google Meet (hangoutsMeet)

calendars और calendarList कलेक्शन में conferenceProperties.allowedConferenceSolutionTypes देखकर यह पता किया जा सकता है कि किसी उपयोगकर्ता के किसी कैलेंडर के लिए, किस तरह का कॉन्फ़्रेंस टाइप काम करता है. settings कलेक्शन में autoAddHangouts सेटिंग देखकर यह भी जानें कि उपयोगकर्ता अपने सभी नए इवेंट के लिए Hangouts बनाए रखना चाहता है या नहीं.

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 देना होगा, जो कोई भी string हो सकता है. कॉन्फ़्रेंस एसिंक्रोनस रूप से बनाई जाती हैं, लेकिन आप अपने अनुरोध की स्थिति की जांच कभी भी अपने उपयोगकर्ताओं को बताने के लिए कर सकते हैं कि क्या हो रहा है.

उदाहरण के लिए, किसी मौजूदा इवेंट के लिए कॉन्फ़्रेंस जनरेट करने का अनुरोध करने के लिए:

JavaScript

const eventPatch = {
  conferenceData: {
    createRequest: {requestId: "7qxalsvy0e"}
  }
};

gapi.client.calendar.events.patch({
  calendarId: "primary",
  eventId: "7cbh8rpc10lrc0ckih9tafss99",
  resource: eventPatch,
  sendNotifications: true,
  conferenceDataVersion: 1
}).execute(function(event) {
  console.log("Conference created for event: %s", event.htmlLink);
});

ऐसा हो सकता है कि इस कॉल के तुरंत जवाब में पूरी तरह से भरा गया conferenceData न हो. इसे status फ़ील्ड में pending स्टेटस कोड से दिखाया जाता है. कॉन्फ़्रेंस की जानकारी भरने के बाद, स्टेटस कोड success में बदल जाता है. entryPoints फ़ील्ड में यह जानकारी होती है कि कौनसे वीडियो और फ़ोन यूआरआई, आपके उपयोगकर्ताओं को डायल इन करने के लिए उपलब्ध कराए जाएंगे.

अगर आपको एक ही कॉन्फ़्रेंस की जानकारी के साथ कई कैलेंडर इवेंट शेड्यूल करने हैं, तो पूरे conferenceData को एक इवेंट से दूसरे इवेंट में कॉपी करें.

कॉपी करना कुछ खास स्थितियों में उपयोगी होता है. उदाहरण के लिए, मान लीजिए कि आपने भर्ती के लिए एक ऐसा आवेदन बनाया है जिसमें उम्मीदवार और इंटरव्यू लेने वाले के लिए अलग-अलग इवेंट सेट अप किए जाते हैं. आपको इंटरव्यू लेने वाले की पहचान की सुरक्षा करनी है, लेकिन आपको यह भी पक्का करना है कि मीटिंग में हिस्सा लेने वाले सभी लोग एक ही कॉन्फ़्रेंस कॉल में शामिल हों.