উন্নত ড্রাইভ লেবেল পরিষেবা

Google Drive Labels উন্নত পরিষেবা ব্যবহার করে আপনার Drive ফাইল এবং ফোল্ডারগুলির জন্য লেবেল তৈরি এবং পরিচালনা করুন। এই উন্নত পরিষেবা ব্যবহার করে, আপনি Apps Script-এ Drive Labels API- এর সমস্ত বৈশিষ্ট্য ব্যবহার করতে পারবেন।

ড্রাইভ লেবেল প্রয়োগ করতে বা সরাতে, অ্যাডভান্সড ড্রাইভ পরিষেবা ব্যবহার করুন।

তথ্যসূত্র

এই পরিষেবা সম্পর্কে আরও তথ্যের জন্য, Google Drive Labels API এর ডকুমেন্টেশন দেখুন। Apps Script-এর সমস্ত উন্নত পরিষেবার মতো, Drive Labels API পরিষেবাটি পাবলিক API-এর মতো একই বস্তু, পদ্ধতি এবং পরামিতি ব্যবহার করে।

সমস্যাগুলি রিপোর্ট করতে এবং অন্যান্য সহায়তা পেতে, Google Drive Labels API সহায়তা নির্দেশিকা দেখুন।

নমুনা কোড

নিচের নমুনা কোডটি API এর সংস্করণ 2 ব্যবহার করে।

তালিকা লেবেল

নিম্নলিখিত কোড নমুনাটি দেখায় যে অনুরোধকারী ব্যবহারকারীর কাছে উপলব্ধ লেবেলের একটি তালিকা কীভাবে পেতে হয়।

উন্নত/ড্রাইভলেবেলস.জিএস
/**
 * List labels available to the user.
 */
function listLabels() {
  let pageToken = null;
  let labels = [];
  do {
    try {
      const response = DriveLabels.Labels.list({
        publishedOnly: true,
        pageToken: pageToken,
      });
      pageToken = response.nextPageToken;
      labels = labels.concat(response.labels);
    } catch (err) {
      // TODO (developer) - Handle exception
      console.log("Failed to list labels with error %s", err.message);
    }
  } while (pageToken != null);

  console.log("Found %d labels", labels.length);
}

একটি লেবেল পান

নিম্নলিখিত কোড নমুনাটি দেখায় কিভাবে একটি একক লেবেলকে তার রিসোর্স নাম (যা লেবেলের স্ট্রিং মান) দিয়ে পেতে হয়। লেবেলের নাম খুঁজে পেতে, API এর মাধ্যমে লেবেলগুলির তালিকা পান অথবা ড্রাইভ লেবেল ম্যানেজার ব্যবহার করুন। লেবেল ম্যানেজার সম্পর্কে আরও তথ্যের জন্য, ড্রাইভ লেবেল পরিচালনা করুন এ যান।

উন্নত/ড্রাইভলেবেলস.জিএস
/**
 * Get a label by name.
 * @param {string} labelName The label name.
 */
function getLabel(labelName) {
  try {
    const label = DriveLabels.Labels.get(labelName, {
      view: "LABEL_VIEW_FULL",
    });
    const title = label.properties.title;
    const fieldsLength = label.fields.length;
    console.log(
      `Fetched label with title: '${title}' and ${fieldsLength} fields.`,
    );
  } catch (err) {
    // TODO (developer) - Handle exception
    console.log("Failed to get label with error %s", err.message);
  }
}

ড্রাইভ আইটেমের জন্য লেবেল তালিকাভুক্ত করুন

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

উন্নত/ড্রাইভলেবেলস.জিএস
/**
 * List Labels on a Drive Item
 * Fetches a Drive Item and prints all applied values along with their to their
 * human-readable names.
 *
 * @param {string} fileId The Drive File ID
 */
function listLabelsOnDriveItem(fileId) {
  try {
    const appliedLabels = Drive.Files.listLabels(fileId);

    console.log(
      "%d label(s) are applied to this file",
      appliedLabels.labels.length,
    );

    for (const appliedLabel of appliedLabels.labels) {
      // Resource name of the label at the applied revision.
      const labelName = `labels/${appliedLabel.id}@${appliedLabel.revisionId}`;

      console.log("Fetching Label: %s", labelName);
      const label = DriveLabels.Labels.get(labelName, {
        view: "LABEL_VIEW_FULL",
      });

      console.log("Label Title: %s", label.properties.title);

      for (const fieldId of Object.keys(appliedLabel.fields)) {
        const fieldValue = appliedLabel.fields[fieldId];
        const field = label.fields.find((f) => f.id === fieldId);

        console.log(
          `Field ID: ${field.id}, Display Name: ${field.properties.displayName}`,
        );
        switch (fieldValue.valueType) {
          case "text":
            console.log("Text: %s", fieldValue.text[0]);
            break;
          case "integer":
            console.log("Integer: %d", fieldValue.integer[0]);
            break;
          case "dateString":
            console.log("Date: %s", fieldValue.dateString[0]);
            break;
          case "user": {
            const user = fieldValue.user
              .map((user) => {
                return `${user.emailAddress}: ${user.displayName}`;
              })
              .join(", ");
            console.log(`User: ${user}`);
            break;
          }
          case "selection": {
            const choices = fieldValue.selection.map((choiceId) => {
              return field.selectionOptions.choices.find(
                (choice) => choice.id === choiceId,
              );
            });
            const selection = choices
              .map((choice) => {
                return `${choice.id}: ${choice.properties.displayName}`;
              })
              .join(", ");
            console.log(`Selection: ${selection}`);
            break;
          }
          default:
            console.log("Unknown: %s", fieldValue.valueType);
            console.log(fieldValue.value);
        }
      }
    }
  } catch (err) {
    // TODO (developer) - Handle exception
    console.log("Failed with error %s", err.message);
  }
}