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

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

রেফারেন্স

এই পরিষেবা সম্পর্কে বিস্তারিত তথ্যের জন্য, স্লাইডস এপিআই (Slides API)-এর রেফারেন্স ডকুমেন্টেশন দেখুন। অ্যাপস স্ক্রিপ্ট (Apps Script)-এর অন্যান্য সকল অ্যাডভান্সড পরিষেবার মতো, অ্যাডভান্সড স্লাইডস পরিষেবাটিও পাবলিক এপিআই (public API)-এর মতোই একই অবজেক্ট, মেথড এবং প্যারামিটার ব্যবহার করে। আরও তথ্যের জন্য, ‘মেথড সিগনেচার কীভাবে নির্ধারণ করা হয়’ (How method signatures are determined ) দেখুন।

সমস্যা জানাতে এবং অন্যান্য সহায়তা পেতে, স্লাইডস সাপোর্ট গাইড দেখুন।

নমুনা কোড

নিম্নলিখিত নমুনা কোডটি API-এর সংস্করণ ১ ব্যবহার করে।

একটি নতুন উপস্থাপনা তৈরি করুন

নিম্নলিখিত উদাহরণটি স্লাইডস অ্যাডভান্সড সার্ভিস ব্যবহার করে কীভাবে একটি নতুন প্রেজেন্টেশন তৈরি করতে হয় তা দেখায়। এটি 'Create a new presentation' রেসিপি স্যাম্পলটির সমতুল্য।

অ্যাডভান্সড/স্লাইডস.জিএস
/**
 * Create a new presentation.
 * @return {string} presentation Id.
 * @see https://developers.google.com/slides/api/reference/rest/v1/presentations/create
 */
function createPresentation() {
  try {
    const presentation = Slides.Presentations.create({
      title: "MyNewPresentation",
    });
    console.log(`Created presentation with ID: ${presentation.presentationId}`);
    return presentation.presentationId;
  } catch (e) {
    // TODO (developer) - Handle exception
    console.log("Failed with error %s", e.message);
  }
}

একটি নতুন স্লাইড তৈরি করুন

নিম্নলিখিত উদাহরণটি দেখায় কিভাবে একটি প্রেজেন্টেশনে, একটি নির্দিষ্ট ইন্ডেক্সে এবং পূর্বনির্ধারিত লেআউট সহ একটি নতুন স্লাইড তৈরি করতে হয়। এটি 'Create a new slide' রেসিপি স্যাম্পলটির সমতুল্য।

অ্যাডভান্সড/স্লাইডস.জিএস
/**
 * Create a new slide.
 * @param {string} presentationId The presentation to add the slide to.
 * @return {Object} slide
 * @see https://developers.google.com/slides/api/reference/rest/v1/presentations/batchUpdate
 */
function createSlide(presentationId) {
  // You can specify the ID to use for the slide, as long as it's unique.
  const pageId = Utilities.getUuid();

  const requests = [
    {
      createSlide: {
        objectId: pageId,
        insertionIndex: 1,
        slideLayoutReference: {
          predefinedLayout: "TITLE_AND_TWO_COLUMNS",
        },
      },
    },
  ];
  try {
    const slide = Slides.Presentations.batchUpdate(
      { requests: requests },
      presentationId,
    );
    console.log(
      `Created Slide with ID: ${slide.replies[0].createSlide.objectId}`,
    );
    return slide;
  } catch (e) {
    // TODO (developer) - Handle Exception
    console.log("Failed with error %s", e.message);
  }
}

পৃষ্ঠা উপাদান অবজেক্ট আইডিগুলি পড়ুন

নিম্নলিখিত উদাহরণটি দেখায় কিভাবে একটি ফিল্ড মাস্ক ব্যবহার করে একটি নির্দিষ্ট স্লাইডের প্রতিটি পেজ এলিমেন্টের অবজেক্ট আইডি পুনরুদ্ধার করা যায়। এটি ' Read element object IDs from a page recipe' স্যাম্পলটির সমতুল্য।

অ্যাডভান্সড/স্লাইডস.জিএস
/**
 * Read page element IDs.
 * @param {string} presentationId The presentation to read from.
 * @param {string} pageId The page to read from.
 * @return {Object} response
 * @see https://developers.google.com/slides/api/reference/rest/v1/presentations.pages/get
 */
function readPageElementIds(presentationId, pageId) {
  // You can use a field mask to limit the data the API retrieves
  // in a get request, or what fields are updated in an batchUpdate.
  try {
    const response = Slides.Presentations.Pages.get(presentationId, pageId, {
      fields: "pageElements.objectId",
    });
    console.log(response);
    return response;
  } catch (e) {
    // TODO (developer) - Handle Exception
    console.log("Failed with error %s", e.message);
  }
}

একটি নতুন টেক্সট বক্স যোগ করুন

নিম্নলিখিত উদাহরণটি দেখায় কিভাবে একটি স্লাইডে একটি নতুন টেক্সট বক্স যোগ করতে হয় এবং তাতে টেক্সট যোগ করতে হয়। এটি 'Add a text box to a slide' রেসিপি স্যাম্পলটির সমতুল্য।

অ্যাডভান্সড/স্লাইডস.জিএস
/**
 * Add a new text box with text to a page.
 * @param {string} presentationId The presentation ID.
 * @param {string} pageId The page ID.
 * @return {Object} response
 * @see https://developers.google.com/slides/api/reference/rest/v1/presentations/batchUpdate
 */
function addTextBox(presentationId, pageId) {
  // You can specify the ID to use for elements you create,
  // as long as the ID is unique.
  const pageElementId = Utilities.getUuid();

  const requests = [
    {
      createShape: {
        objectId: pageElementId,
        shapeType: "TEXT_BOX",
        elementProperties: {
          pageObjectId: pageId,
          size: {
            width: {
              magnitude: 150,
              unit: "PT",
            },
            height: {
              magnitude: 50,
              unit: "PT",
            },
          },
          transform: {
            scaleX: 1,
            scaleY: 1,
            translateX: 200,
            translateY: 100,
            unit: "PT",
          },
        },
      },
    },
    {
      insertText: {
        objectId: pageElementId,
        text: "My Added Text Box",
        insertionIndex: 0,
      },
    },
  ];
  try {
    const response = Slides.Presentations.batchUpdate(
      { requests: requests },
      presentationId,
    );
    console.log(
      `Created Textbox with ID: ${response.replies[0].createShape.objectId}`,
    );
    return response;
  } catch (e) {
    // TODO (developer) - Handle Exception
    console.log("Failed with error %s", e.message);
  }
}

টেক্সটের আকৃতি বিন্যাস করুন

নিম্নলিখিত উদাহরণটি দেখায় কিভাবে একটি শেপের টেক্সট ফরম্যাট করতে হয়, এর রঙ, ফন্ট আপডেট করে এবং টেক্সটের নিচে আন্ডারলাইন করে। এটি 'Format text in a shape or textbox' রেসিপি স্যাম্পলটির সমতুল্য।

অ্যাডভান্সড/স্লাইডস.জিএস
/**
 * Format the text in a shape.
 * @param {string} presentationId The presentation ID.
 * @param {string} shapeId The shape ID.
 * @return {Object} replies
 * @see https://developers.google.com/slides/api/reference/rest/v1/presentations/batchUpdate
 */
function formatShapeText(presentationId, shapeId) {
  const requests = [
    {
      updateTextStyle: {
        objectId: shapeId,
        fields: "foregroundColor,bold,italic,fontFamily,fontSize,underline",
        style: {
          foregroundColor: {
            opaqueColor: {
              themeColor: "ACCENT5",
            },
          },
          bold: true,
          italic: true,
          underline: true,
          fontFamily: "Corsiva",
          fontSize: {
            magnitude: 18,
            unit: "PT",
          },
        },
        textRange: {
          type: "ALL",
        },
      },
    },
  ];
  try {
    const response = Slides.Presentations.batchUpdate(
      { requests: requests },
      presentationId,
    );
    return response.replies;
  } catch (e) {
    // TODO (developer) - Handle Exception
    console.log("Failed with error %s", e.message);
  }
}

সর্বোত্তম অনুশীলন

ব্যাচ আপডেট

স্লাইডস অ্যাডভান্সড সার্ভিস ব্যবহার করার সময়, লুপের মধ্যে batchUpdate কল না করে একাধিক অনুরোধকে একটি অ্যারেতে একত্রিত করুন।

লুপের মধ্যে batchUpdate কল করবেন না

var titles = ["slide 1", "slide 2"];
for (var i = 0; i < titles.length; i++) {
  Slides.Presentations.batchUpdate(preso, {
    requests: [{
      createSlide: ...
    }]
  });
}

করণীয় — আপডেটগুলোর একটি অ্যারে দিয়ে batchUpdate কল করুন।

var requests = [];
var titles = ["slide 1", "slide 2"];
for (var i = 0; i < titles.length; i++) {
  requests.push({ createSlide: ... });
}

Slides.Presentations.batchUpdate(preso, {
  requests: requests
});