লেবেল

এই পৃষ্ঠায় ব্যাখ্যা করা হয়েছে লেবেল কী, ক্যালেন্ডারে সেগুলি কীভাবে পরিচালনা করা হয় এবং গুগল ক্যালেন্ডার এপিআই ব্যবহার করে কীভাবে ইভেন্টগুলিতে লেবেল যুক্ত করা যায়।

গুগল ক্যালেন্ডার আপনাকে আপনার ইভেন্টগুলোকে নিজস্ব রঙ এবং নাম দিয়ে সেগুলোর চেহারা সাজিয়ে নেওয়ার সুযোগ দেয়। আগে, ইভেন্টগুলো একটি নির্দিষ্ট সূচক-ভিত্তিক রঙের ( colorId ) মধ্যে সীমাবদ্ধ ছিল। লেবেলের মাধ্যমে, আপনি প্রতিটি ক্যালেন্ডারের জন্য একটি নমনীয় ও নিজস্ব রঙের প্যালেট নির্ধারণ করতে পারেন এবং এই লেবেলগুলো সরাসরি ইভেন্টগুলোতে প্রয়োগ করতে পারেন।

ক্যালেন্ডারে লেবেলগুলি পরিচালনা করুন

ক্যালেন্ডারস রিসোর্সের labelProperties প্রপার্টি ব্যবহার করে আপনি প্রতিটি ক্যালেন্ডারের জন্য সর্বোচ্চ ২০০টি কাস্টম লেবেল নির্ধারণ করতে পারেন।

লেবেল পরিচালনা করতে Calendars.insert বা Calendars.update মেথডগুলো ব্যবহার করুন। প্রতিটি লেবেলের জন্য একটি id , হেক্সাডেসিমেল ফরম্যাটে একটি backgroundColor এবং একটি ঐচ্ছিক name প্রয়োজন।

ক্যালেন্ডার সম্পদের উপস্থাপনা

{
  "kind": "calendar#calendar",
  "id": "primary",
  "summary": "My Team Calendar",
  "labelProperties": {
    "eventLabels": [
      {
        "id": "42617328-8756-4291-8273-192837465647",
        "backgroundColor": "#039be5",
        "name": "Important Project"
      },
      {
        "id": "19283746-9182-4736-8271-918273645261",
        "backgroundColor": "#33b679",
        "name": "Team Meeting"
      }
    ]
  }
}

উদাহরণ: ক্যালেন্ডারে লেবেল যোগ করা এবং সরানো

লেবেল যোগ বা অপসারণ করতে, প্রথমে ক্যালেন্ডার থেকে লেবেলের বর্তমান তালিকাটি সংগ্রহ করুন, আপনার কোডে তালিকাটি পরিবর্তন করুন এবং তারপরে অন্যান্য লেবেল ওভাররাইট হওয়া এড়াতে আপডেট করা তালিকা দিয়ে ক্যালেন্ডারটি আপডেট করুন।

নিম্নলিখিত নমুনাগুলিতে দেখানো হয়েছে কিভাবে একটি ক্যালেন্ডার পুনরুদ্ধার করতে হয়, 11111111-2222-3333-4444-555555555555 আইডি সহ একটি লেবেল সরাতে হয়, দুটি নতুন লেবেল ( 22222222-3333-4444-5555-666666666666 এবং 33333333-4444-5555-6666-777777777777 ) যোগ করতে হয় এবং ক্যালেন্ডারটি আপডেট করতে হয়:

যান

// Refer to the Go quickstart on how to setup the service:
// https://developers.google.com/workspace/calendar/quickstart/go

// 1. Read the calendar to get existing labels
calendar, err := srv.Calendars.Get("primary").Do()
if err != nil {
    log.Fatalf("Unable to retrieve calendar: %v", err)
}

if calendar.LabelProperties == nil {
    calendar.LabelProperties = &calendar.LabelProperties{}
}
labels := calendar.LabelProperties.EventLabels

// 2. Remove a label with a specific ID (UUID format)
targetIdToRemove := "11111111-2222-3333-4444-555555555555"
var updatedLabels []*calendar.EventLabel
for _, label := range labels {
    if label.Id != targetIdToRemove {
        updatedLabels = append(updatedLabels, label)
    }
}
labels = updatedLabels

// 3. Add 2 new labels with UUID IDs
labels = append(labels, &calendar.EventLabel{
    Id:              "22222222-3333-4444-5555-666666666666",
    BackgroundColor: "#8e24aa",
    Name:            "Design Work",
})
labels = append(labels, &calendar.EventLabel{
    Id:              "33333333-4444-5555-6666-777777777777",
    BackgroundColor: "#f4511e",
    Name:            "Urgent Review",
})

// 4. Update the calendar with the new list
calendar.LabelProperties.EventLabels = labels
updatedCalendar, err := srv.Calendars.Update("primary", calendar).Do()
if err != nil {
    log.Fatalf("Unable to update calendar: %v", err)
}
fmt.Printf("Calendar updated: %s\n", updatedCalendar.Summary)

জাভা

// Refer to the Java quickstart on how to setup the service:
// https://developers.google.com/workspace/calendar/quickstart/java

// 1. Read the calendar to get existing labels
Calendar calendar = service.calendars().get("primary").execute();

LabelProperties labelProperties = calendar.getLabelProperties();
if (labelProperties == null) {
  labelProperties = new LabelProperties();
}
List<EventLabel> labels = labelProperties.getEventLabels();
if (labels == null) {
  labels = new ArrayList<>();
} else {
  // Create a mutable copy since the returned list might be immutable
  labels = new ArrayList<>(labels);
}

// 2. Remove a label with a specific ID (UUID format)
String targetIdToRemove = "11111111-2222-3333-4444-555555555555";
labels.removeIf(label -> targetIdToRemove.equals(label.getId()));

// 3. Add 2 new labels with UUID IDs
labels.add(new EventLabel()
    .setId("22222222-3333-4444-5555-666666666666")
    .setBackgroundColor("#8e24aa")
    .setName("Design Work"));

labels.add(new EventLabel()
    .setId("33333333-4444-5555-6666-777777777777")
    .setBackgroundColor("#f4511e")
    .setName("Urgent Review"));

// 4. Update the calendar with the new list
labelProperties.setEventLabels(labels);
calendar.setLabelProperties(labelProperties);

Calendar updatedCalendar = service.calendars().update("primary", calendar)
    .execute();

System.out.printf("Calendar updated: %s\n", updatedCalendar.getSummary());

জাভাস্ক্রিপ্ট

// Refer to the Node.js quickstart on how to setup the service:
// https://developers.google.com/workspace/calendar/quickstart/nodejs

// 1. Retrieve the calendar resource
calendar.calendars.get({
  calendarId: 'primary'
}, (err, res) => {
  if (err) return console.log('The API returned an error: ' + err);

  // Extract existing labels from the calendar resource
  const cal = res.data;
  if (!cal.labelProperties) {
    cal.labelProperties = {};
  }
  if (!cal.labelProperties.eventLabels) {
    cal.labelProperties.eventLabels = [];
  }

  // 2. Remove a label with a specific ID (UUID format)
  const targetIdToRemove = '11111111-2222-3333-4444-555555555555';
  cal.labelProperties.eventLabels = cal.labelProperties.eventLabels.filter(
    label => label.id !== targetIdToRemove
  );

  // 3. Add 2 new labels with UUID IDs
  cal.labelProperties.eventLabels.push({
    id: '22222222-3333-4444-5555-666666666666',
    backgroundColor: '#8e24aa',
    name: 'Design Work'
  });
  cal.labelProperties.eventLabels.push({
    id: '33333333-4444-5555-6666-777777777777',
    backgroundColor: '#f4511e',
    name: 'Urgent Review'
  });

  // 4. Update the calendar with the new list
  calendar.calendars.update({
    calendarId: 'primary',
    resource: cal
  }, (updateErr, updateRes) => {
    if (updateErr) return console.log('Update failed: ' + updateErr);
    console.log(`Calendar updated: ${updateRes.data.summary}`);
  });
});

পাইথন

# Refer to the Python quickstart on how to setup the service:
# https://developers.google.com/workspace/calendar/quickstart/python

# 1. Read the calendar to get existing labels
calendar = service.calendars().get(calendarId='primary').execute()

label_properties = calendar.setdefault('labelProperties', {})
labels = label_properties.setdefault('eventLabels', [])

# 2. Remove a label with a specific ID (UUID format)
target_id_to_remove = "11111111-2222-3333-4444-555555555555"
labels = [l for l in labels if l.get('id') != target_id_to_remove]

# 3. Add 2 new labels with UUID IDs
labels.append({
    'id': '22222222-3333-4444-5555-666666666666',
    'backgroundColor': '#8e24aa',
    'name': 'Design Work'
})
labels.append({
    'id': '33333333-4444-5555-6666-777777777777',
    'backgroundColor': '#f4511e',
    'name': 'Urgent Review'
})

# 4. Update the calendar with the new list
label_properties['eventLabels'] = labels
calendar['labelProperties'] = label_properties

updated_calendar = service.calendars().update(
    calendarId='primary',
    body=calendar
).execute()

print(f"Calendar updated: {updated_calendar.get('summary')}")

HTTP

নিম্নলিখিত সাধারণ HTTP উদাহরণটি নতুন লেবেল তালিকা দিয়ে ক্যালেন্ডার আপডেট করার চূড়ান্ত PUT অনুরোধটি দেখাচ্ছে। প্রথমে নিশ্চিত করুন যে আপনি এগুলোকে বিদ্যমান লেবেলগুলোর সাথে একীভূত করেছেন।

PUT https://www.googleapis.com/calendar/v3/calendars/primary
Authorization: Bearer [YOUR_ACCESS_TOKEN]
Content-Type: application/json

{
  "summary": "Updated Team Calendar",
  "labelProperties": {
    "eventLabels": [
      {
        "id": "22222222-3333-4444-5555-666666666666",
        "backgroundColor": "#8e24aa",
        "name": "Design Work"
      },
      {
        "id": "33333333-4444-5555-6666-777777777777",
        "backgroundColor": "#f4511e",
        "name": "Urgent Review"
      }
    ]
  }
}

ইভেন্টগুলিতে লেবেল নির্ধারণ করুন

ক্যালেন্ডারে একবার লেবেল নির্ধারণ করা হয়ে গেলে, আপনি Events রিসোর্সের eventLabelId প্রপার্টি সেট করার মাধ্যমে সেগুলোকে স্বতন্ত্র ইভেন্টগুলোতে বরাদ্দ করতে পারেন।

insert , update বা patch মেথডগুলো কল করার সময় আপনি এই প্রপার্টিটি সেট বা পরিবর্তন করতে পারেন।

ইভেন্ট রিসোর্স উপস্থাপনা

{
  "kind": "calendar#event",
  "id": "sample-event-id",
  "summary": "Review Design Specs",
  "start": {
    "dateTime": "2026-07-01T10:00:00Z"
  },
  "end": {
    "dateTime": "2026-07-01T11:00:00Z"
  },
  "eventLabelId": "22222222-3333-4444-5555-666666666666"
}

উদাহরণ: একটি লেবেল সহ একটি ইভেন্ট তৈরি করুন

নিম্নলিখিত নমুনাগুলি দেখায় কিভাবে একটি কাস্টম লেবেল সহ একটি ইভেন্ট তৈরি করতে হয়:

যান

// Refer to the Go quickstart on how to setup the service:
// https://developers.google.com/workspace/calendar/quickstart/go

event := &calendar.Event{
    Summary: "Design Sync",
    Start: &calendar.EventDateTime{
        DateTime: "2026-07-02T14:00:00Z",
    },
    End: &calendar.EventDateTime{
        DateTime: "2026-07-02T15:00:00Z",
    },
    EventLabelId: "22222222-3333-4444-5555-666666666666",
}

createdEvent, err := srv.Events.Insert("primary", event).EventLabelVersion(1).Do()
if err != nil {
    log.Fatalf("Unable to create event: %v", err)
}
fmt.Printf("Event created: %s\n", createdEvent.HtmlLink)

জাভা

// Refer to the Java quickstart on how to setup the service:
// https://developers.google.com/workspace/calendar/quickstart/java

Event event = new Event()
    .setSummary("Design Sync")
    .setStart(new EventDateTime().setDateTime(new DateTime("2026-07-02T14:00:00Z")))
    .setEnd(new EventDateTime().setDateTime(new DateTime("2026-07-02T15:00:00Z")))
    .setEventLabelId("22222222-3333-4444-5555-666666666666");

Event createdEvent = service.events().insert("primary", event)
    .setEventLabelVersion(1L)
    .execute();

System.out.printf("Event created: %s\n", createdEvent.getHtmlLink());

জাভাস্ক্রিপ্ট

// Refer to the Node.js quickstart on how to setup the service:
// https://developers.google.com/workspace/calendar/quickstart/nodejs

const event = {
  summary: 'Design Sync',
  start: {
    dateTime: '2026-07-02T14:00:00Z',
  },
  end: {
    dateTime: '2026-07-02T15:00:00Z',
  },
  eventLabelId: '22222222-3333-4444-5555-666666666666',
};

calendar.events.insert({
  calendarId: 'primary',
  resource: event,
  eventLabelVersion: 1,
}, (err, res) => {
  if (err) return console.log('The API returned an error: ' + err);
  console.log(`Event created: ${res.data.htmlLink}`);
});

পাইথন

# Refer to the Python quickstart on how to setup the service:
# https://developers.google.com/workspace/calendar/quickstart/python

event = {
    'summary': 'Design Sync',
    'start': {
        'dateTime': '2026-07-02T14:00:00Z',
    },
    'end': {
        'dateTime': '2026-07-02T15:00:00Z',
    },
    'eventLabelId': '22222222-3333-4444-5555-666666666666'
}

event = service.events().insert(
    calendarId='primary',
    body=event,
    eventLabelVersion=1
).execute()

print(f"Event created: {event.get('htmlLink')}")

HTTP

POST https://www.googleapis.com/calendar/v3/calendars/primary/events?eventLabelVersion=1
Authorization: Bearer [YOUR_ACCESS_TOKEN]
Content-Type: application/json

{
  "summary": "Design Sync",
  "start": {
    "dateTime": "2026-07-02T14:00:00Z"
  },
  "end": {
    "dateTime": "2026-07-02T15:00:00Z"
  },
  "eventLabelId": "22222222-3333-4444-5555-666666666666"
}

কোনো ইভেন্ট থেকে বিদ্যমান লেবেল সরাতে, eventLabelId একটি খালি স্ট্রিং ( "" ) হিসেবে সেট করুন অথবা update অনুরোধে ফিল্ডটি সম্পূর্ণরূপে বাদ দিন।