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

এই পৃষ্ঠাটি বর্ণনা করে কিভাবে একটি বিদ্যমান Google স্লাইড উপস্থাপনায় স্লাইড যোগ করতে হয়।

স্লাইড

একটি স্লাইড উপস্থাপনার প্রতিটি পৃথক পৃষ্ঠা একটি স্লাইড

উপস্থাপনায় একটি স্লাইড যোগ করতে, আপনার উপস্থাপনা আইডি প্রয়োজন। আপনি স্লাইডে উপস্থাপনাটি খুলে এবং এর URL দেখে উপস্থাপনার আইডি খুঁজে পেতে পারেন:

https://docs.google.com/presentation/d/presentationID/edit

একটি স্লাইড যোগ করতে, উপস্থাপনা আইডি সহ batchUpdate() পদ্ধতি ব্যবহার করুন এবং অনুরোধের বডিতে একটি CreateSlideRequest অন্তর্ভুক্ত করুন। নতুন স্লাইডের আইডি প্রতিক্রিয়া বডিতে ফেরত দেওয়া হয়।

উদাহরণ

নিচের উদাহরণটি দেখায় কিভাবে একটি উপস্থাপনায় একটি স্লাইড যোগ করতে হয়। CreateSlideRequest এর জন্য সমস্ত ক্ষেত্র ঐচ্ছিক। এই উদাহরণটি TITLE_AND_TWO_COLUMNS লেআউট এবং একটি স্পষ্ট অবজেক্ট আইডি সহ দ্বিতীয় স্লাইড হিসাবে স্লাইড তৈরি করে৷

অ্যাপস স্ক্রিপ্ট

slides/api/Snippets.gs
/**
 * Creates a slide
 * @param {string} presentationId
 * @param {string} pageId
 * @returns {*}
 */
function createSlide(presentationId, pageId) {
  // See Presentation.insertSlide(...) to learn how to add a slide using SlidesApp.
  // http://developers.google.com/apps-script/reference/slides/presentation#appendslidelayout
  const requests = [{
    createSlide: {
      objectId: pageId,
      insertionIndex: '1',
      slideLayoutReference: {
        predefinedLayout: 'TITLE_AND_TWO_COLUMNS'
      }
    }
  }];

  // If you wish to populate the slide with elements, add element create requests here,
  // using the pageId.

  // Execute the request.
  try {
    const createSlideResponse = Slides.Presentations.batchUpdate({
      requests: requests
    }, presentationId);
    console.log('Created slide with ID: %s', createSlideResponse.replies[0].createSlide.objectId);
    return createSlideResponse;
  } catch (err) {
    // TODO (Developer) - Handle exception
    console.log('Failed with error: %s', err.error);
  }
};

যাওয়া

slides/snippets/presentations.go
// Add a slide at index 1 using the predefined "TITLE_AND_TWO_COLUMNS" layout
// and the ID "MyNewSlide_001".
slideId := "MyNewSlide_001"
requests := []*slides.Request{{
	CreateSlide: &slides.CreateSlideRequest{
		ObjectId:       slideId,
		InsertionIndex: 1,
		SlideLayoutReference: &slides.LayoutReference{
			PredefinedLayout: "TITLE_AND_TWO_COLUMNS",
		},
	},
}}

// If you wish to populate the slide with elements, add create requests here,
// using the slide ID specified above.

// Execute the request.
body := &slides.BatchUpdatePresentationRequest{
	Requests: requests,
}
response, err := slidesService.Presentations.BatchUpdate(presentationId, body).Do()
if err != nil {
	log.Fatalf("Unable to create slide. %v", err)
}
fmt.Printf("Created slide with ID: %s", response.Replies[0].CreateSlide.ObjectId)

জাভা

slides/snippets/src/main/java/CreateSlide.java
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.googleapis.json.GoogleJsonError;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.slides.v1.Slides;
import com.google.api.services.slides.v1.SlidesScopes;
import com.google.api.services.slides.v1.model.BatchUpdatePresentationRequest;
import com.google.api.services.slides.v1.model.BatchUpdatePresentationResponse;
import com.google.api.services.slides.v1.model.CreateSlideRequest;
import com.google.api.services.slides.v1.model.CreateSlideResponse;
import com.google.api.services.slides.v1.model.LayoutReference;
import com.google.api.services.slides.v1.model.Request;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/* Class to demonstrate the use of Create Slides API */
public class CreateSlide {
  /**
   * Creates a new slide.
   *
   * @param presentationId - id of the presentation.
   * @return slide id
   * @throws IOException - if credentials file not found.
   */
  public static BatchUpdatePresentationResponse createSlide(String presentationId)
      throws IOException {
        /* Load pre-authorized user credentials from the environment.
           TODO(developer) - See https://developers.google.com/identity for
            guides on implementing OAuth2 for your application. */
    GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
        .createScoped(Collections.singleton(SlidesScopes.PRESENTATIONS));
    HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(
        credentials);

    // Create the slides API client
    Slides service = new Slides.Builder(new NetHttpTransport(),
        GsonFactory.getDefaultInstance(),
        requestInitializer)
        .setApplicationName("Slides samples")
        .build();

    // Add a slide at index 1 using the predefined "TITLE_AND_TWO_COLUMNS" layout
    List<Request> requests = new ArrayList<>();
    String slideId = "MyNewSlide_001";
    BatchUpdatePresentationResponse response = null;
    try {
      requests.add(new Request()
          .setCreateSlide(new CreateSlideRequest()
              .setObjectId(slideId)
              .setInsertionIndex(1)
              .setSlideLayoutReference(new LayoutReference()
                  .setPredefinedLayout("TITLE_AND_TWO_COLUMNS"))));

      // If you wish to populate the slide with elements, add create requests here,
      // using the slide ID specified above.

      // Execute the request.
      BatchUpdatePresentationRequest body =
          new BatchUpdatePresentationRequest().setRequests(requests);
      response = service.presentations().batchUpdate(presentationId, body).execute();
      CreateSlideResponse createSlideResponse = response.getReplies().get(0).getCreateSlide();
      // Prints the slide id.
      System.out.println("Created slide with ID: " + createSlideResponse.getObjectId());
    } catch (GoogleJsonResponseException e) {
      // TODO(developer) - handle error appropriately
      GoogleJsonError error = e.getDetails();
      if (error.getCode() == 400) {
        System.out.printf(" Id '%s' should be unique among all pages and page elements.\n",
            presentationId);
      } else if (error.getCode() == 404) {
        System.out.printf("Presentation not found with id '%s'.\n", presentationId);
      } else {
        throw e;
      }
    }
    return response;
  }
}

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

slides/snippets/slides_create_slide.js
function createSlide(presentationId, pageId, callback) {
  const requests = [
    {
      createSlide: {
        objectId: pageId,
        insertionIndex: '1',
        slideLayoutReference: {
          predefinedLayout: 'TITLE_AND_TWO_COLUMNS',
        },
      },
    },
  ];
  // If you wish to populate the slide with elements, add element create requests here,
  // using the pageId.
  // Execute the request.
  try {
    gapi.client.slides.presentations
        .batchUpdate({
          presentationId: presentationId,
          requests: requests,
        })
        .then((createSlideResponse) => {
          const objectId =
          createSlideResponse.result.replies[0].createSlide.objectId;
          console.log(`Created slide with ID: ${objectId}`);
          if (callback) callback(createSlideResponse);
        });
  } catch (err) {
    document.getElementById('content').innerText = err.message;
    return;
  }
}

Node.js

slides/snippets/slides_create_slide.js
/**
 * Creates a new slide in a presentation.
 * @param {string} presentationId The presentation ID.
 * @param {string} pageId The object ID for the new slide.
 */
async function createSlide(presentationId, pageId) {
  const {GoogleAuth} = require('google-auth-library');
  const {google} = require('googleapis');

  const auth = new GoogleAuth({
    scopes: 'https://www.googleapis.com/auth/presentations',
  });

  const service = google.slides({version: 'v1', auth});
  const requests = [
    {
      createSlide: {
        objectId: pageId,
        insertionIndex: '1',
        slideLayoutReference: {
          predefinedLayout: 'TITLE_AND_TWO_COLUMNS',
        },
      },
    },
  ];
  // If you wish to populate the slide with elements, add element create requests here,
  // using the pageId.

  // Execute the request.
  try {
    const res = await service.presentations.batchUpdate({
      presentationId,
      resource: {
        requests,
      },
    });
    console.log(
        `Created slide with ID: ${res.data.replies[0].createSlide.objectId}`,
    );
    return res;
  } catch (err) {
    // TODO (developer) - handle exception
    throw err;
  }
}

পিএইচপি

slides/snippets/src/SlidesCreateSlide.php
use Google\Client;
use Google\Service\Drive;
use Google\Service\Slides\Request;
use Google\Service\Slides\BatchUpdatePresentationRequest;

function createSlide($presentationId, $pageId)
{
    /* Load pre-authorized user credentials from the environment.
   TODO(developer) - See https://developers.google.com/identity for
    guides on implementing OAuth2 for your application. */
    $client = new Google\Client();
    $client->useApplicationDefaultCredentials();
    $client->addScope(Google\Service\Drive::DRIVE);
    $slidesService = new Google_Service_Slides($client);
    try {
        $requests = array();
        $requests[] = new Google_Service_Slides_Request(array(
            'createSlide' => array(
                'objectId' => $pageId,
                'insertionIndex' => 1,
                'slideLayoutReference' => array(
                    'predefinedLayout' => 'TITLE_AND_TWO_COLUMNS'
                )
            )
        ));
        $batchUpdateRequest = new Google_Service_Slides_BatchUpdatePresentationRequest(array(
            'requests' => $requests
        ));

        //execute the request 
        $response = $slidesService->presentations->batchUpdate($presentationId, $batchUpdateRequest);
        $createSlideResponse = $response->getReplies()[0]->getCreateSlide();
        printf("Created slide with ID: %s\n", $createSlideResponse->getObjectId());
        return $response;
    } catch (Exception $e) {
        echo 'Message: ' . $e->getMessage();
    }
}

পাইথন

slides/snippets/slides_create_slide.py
import google.auth
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError


def create_slide(presentation_id, page_id):
  """
  Creates the Presentation the user has access to.
  Load pre-authorized user credentials from the environment.
  TODO(developer) - See https://developers.google.com/identity
  for guides on implementing OAuth2 for the application.\n
  """
  creds, _ = google.auth.default()
  # pylint: disable=maybe-no-member
  try:
    service = build("slides", "v1", credentials=creds)
    # Add a slide at index 1 using the predefined
    # 'TITLE_AND_TWO_COLUMNS' layout and the ID page_id.
    requests = [
        {
            "createSlide": {
                "objectId": page_id,
                "insertionIndex": "1",
                "slideLayoutReference": {
                    "predefinedLayout": "TITLE_AND_TWO_COLUMNS"
                },
            }
        }
    ]

    # If you wish to populate the slide with elements,
    # add element create requests here, using the page_id.

    # Execute the request.
    body = {"requests": requests}
    response = (
        service.presentations()
        .batchUpdate(presentationId=presentation_id, body=body)
        .execute()
    )
    create_slide_response = response.get("replies")[0].get("createSlide")
    print(f"Created slide with ID:{(create_slide_response.get('objectId'))}")
  except HttpError as error:
    print(f"An error occurred: {error}")
    print("Slides not created")
    return error

  return response


if __name__ == "__main__":
  # Put the presentation_id, Page_id of slides whose list needs
  # to be submitted.
  create_slide("12SQU9Ik-ShXecJoMtT-LlNwEPiFR7AadnxV2KiBXCnE", "My4ndpage")

রুবি

slides/snippets/lib/file_snippets.rb
body = Google::Apis::SlidesV1::Presentation.new
requests = [{
  create_slide: {
    object_id_prop:         page_id,
    insertion_index:        '1',
    slide_layout_reference: {
      predefined_layout: 'TITLE_AND_TWO_COLUMNS'
    }
  }
}]

# If you wish to populate the slide with elements, add element create requests here,
# using the page_id.

# Execute the request.
req = Google::Apis::SlidesV1::BatchUpdatePresentationRequest.new(requests: requests)
response = slides_service.batch_update_presentation(presentation_id, req)
create_slide_response = response.replies[0].create_slide
puts "Created slide with ID: #{create_slide_response.object_id}"

আপনি স্লাইড তৈরি করার পরে, আপনি এটিতে পাঠ্য এবং আকার যোগ করতে পারেন।

স্থানধারক পূরণ করুন

লেআউটে সাধারণত প্লেসহোল্ডার আকার থাকে যা স্লাইড তৈরি করার সময় কপি করা হয়। CreateSlideRequest আপনাকে placeholderIdMappings ক্ষেত্রের মাধ্যমে এই কপি করা স্থানধারকগুলির জন্য ব্যবহৃত অবজেক্ট আইডি নির্দিষ্ট করতে দেয়। এটি আপনাকে একই batchUpdate অনুরোধে অনুলিপি করা স্থানধারকগুলিকে সংশোধন করতে দেয়, যা কর্মক্ষমতা উন্নত করে এবং কোটা সংরক্ষণ করে। আরও তথ্যের জন্য, CreateSlideRequest নমুনা দেখুন।