/** * Creates a presentation * @returns {*} the created presentation */functioncreatePresentation(){try{constpresentation=Slides.Presentations.create({title:title});console.log('CreatedpresentationwithID:%s',presentation.presentationId);returnpresentation;}catch(err){// TODO (Developer) - Handle exceptionconsole.log('Failedwitherror:%s',err.error);}};
// Create a presentation and request a PresentationId.p:=&slides.Presentation{Title:"Title",}presentation,err:=slidesService.Presentations.Create(p).Fields("presentationId",).Do()iferr!=nil{log.Fatalf("Unable to create presentation. %v",err)}fmt.Printf("Created presentation with ID: %s",presentation.PresentationId)
importcom.google.api.client.http.HttpRequestInitializer;importcom.google.api.client.http.javanet.NetHttpTransport;importcom.google.api.client.json.gson.GsonFactory;importcom.google.api.services.slides.v1.Slides;importcom.google.api.services.slides.v1.SlidesScopes;importcom.google.api.services.slides.v1.model.Presentation;importcom.google.auth.http.HttpCredentialsAdapter;importcom.google.auth.oauth2.GoogleCredentials;importjava.io.IOException;importjava.util.Collections;/* Class to demonstrate the use of Slides Create Presentation API */publicclassCreatePresentation{/** * Creates a new presentation. * * @param title - the name of the presentation to be created * @return presentation id * @throws IOException - if credentials file not found. */publicstaticStringcreatePresentation(Stringtitle)throwsIOException{/* Load pre-authorized user credentials from the environment. TODO(developer) - See https://developers.google.com/identity for guides on implementing OAuth2 for your application. */GoogleCredentialscredentials=GoogleCredentials.getApplicationDefault().createScoped(Collections.singleton(SlidesScopes.PRESENTATIONS));HttpRequestInitializerrequestInitializer=newHttpCredentialsAdapter(credentials);// Create the slides API clientSlidesservice=newSlides.Builder(newNetHttpTransport(),GsonFactory.getDefaultInstance(),requestInitializer).setApplicationName("Slides samples").build();// Creates a blank presentation with a specified title.Presentationpresentation=newPresentation().setTitle(title);presentation=service.presentations().create(presentation).setFields("presentationId").execute();// Prints the newly created presentation id.System.out.println("Created presentation with ID: "+presentation.getPresentationId());returnpresentation.getPresentationId();}}
functioncreatePresentation(title,callback){try{gapi.client.slides.presentations.create({title:title,}).then((response)=>{console.log(`Created presentation with ID: ${response.result.presentationId}`);if(callback)callback(response);});}catch(err){document.getElementById('content').innerText=err.message;return;}}
/** * Creates a Google Slide presentation. * @param {string} title The presentation title. */asyncfunctioncreatePresentation(title){const{GoogleAuth}=require('google-auth-library');const{google}=require('googleapis');constauth=newGoogleAuth({scopes:'https://www.googleapis.com/auth/presentations',});constservice=google.slides({version:'v1',auth});try{constpresentation=awaitservice.presentations.create({title,});console.log(`Created presentation with ID: ${presentation.data.presentationId}`,);returnpresentation;}catch(err){// TODO (developer) - Handle exceptionthrowerr;}}
use Google\Client;use Google\Service\Drive;use Google\Service\Slides;use Google\Service\Slides\Request;function createPresentation($title){ /* 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); $service = new Google_Service_Slides($client); try { $presentation = new Google_Service_Slides_Presentation($title); //creating a presentation $presentation = $service->presentations->create($presentation); printf("Created presentation with ID: %s\n", $presentation->presentationId); return $presentation; } catch (Exception $e) { echo 'Message: ' . $e->getMessage(); }}
importgoogle.authfromgoogleapiclient.discoveryimportbuildfromgoogleapiclient.errorsimportHttpErrordefcreate_presentation(title):""" 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. """creds,_=google.auth.default()# pylint: disable=maybe-no-membertry:service=build("slides","v1",credentials=creds)body={"title":title}presentation=service.presentations().create(body=body).execute()print(f"Created presentation with ID:{(presentation.get('presentationId'))}")returnpresentationexceptHttpErroraserror:print(f"An error occurred: {error}")print("presentation not created")returnerrorif__name__=="__main__":# Put the title of the presentationcreate_presentation("finalp")
body=Google::Apis::SlidesV1::Presentation.newbody.title=titlepresentation=slides_service.create_presentation(body)puts"Created presentation with ID: #{presentation.presentation_id}"
العمل مع مجلدات Google Drive
لا يتوفّر خيار لإنشاء عرض تقديمي مباشرةً في مجلد محدّد على Drive باستخدام Google Slides API. يتم تلقائيًا حفظ العرض التقديمي الذي تم إنشاؤه في المجلد الجذر للمستخدم على Drive.
ومع ذلك، هناك خياران بديلان لحفظ ملف في مجلد على Drive:
بعد إنشاء العرض التقديمي، يمكنك نقله إلى مجلد محدّد باستخدام الطريقة files.update من واجهة برمجة التطبيقات Drive API. لمزيد من المعلومات عن نقل الملفات، يُرجى الاطّلاع على مقالة نقل الملفات بين المجلدات.
أضِف عرضًا تقديميًا فارغًا إلى مجلد باستخدام الطريقة files.create من Drive API، مع تحديد application/vnd.google-apps.presentation على أنّه mimeType. لمزيد من المعلومات عن إنشاء الملفات، يُرجى الاطّلاع على مقالة إنشاء ملف في مجلد.
في أيّ من الخيارَين، عليك إضافة نطاقات Drive API المناسبة لتفويض الطلب.
/** * create a presentation and copy it * @param {string} presentationId - ID of presentation to copy * @returns {*} the copy's presentation id */functioncopyPresentation(presentationId){constcopyTitle='CopyTitle';letcopyFile={title:copyTitle,parents:[{id:'root'}]};try{copyFile=Drive.Files.copy(copyFile,presentationId);// (optional) copyFile.id can be returned directlyconstpresentationCopyId=copyFile.id;returnpresentationCopyId;}catch(err){// TODO (Developer) - Handle exceptionconsole.log('Failedwitherror:%s',err.error);}};
// Copy a presentation.file:=drive.File{Title:title,}presentationCopyFile,err:=driveService.Files.Copy(id,&file).Do()iferr!=nil{log.Fatalf("Unable to copy presentation. %v",err)}presentationCopyId:=presentationCopyFile.Id
importcom.google.api.client.googleapis.json.GoogleJsonError;importcom.google.api.client.googleapis.json.GoogleJsonResponseException;importcom.google.api.client.http.HttpRequestInitializer;importcom.google.api.client.http.javanet.NetHttpTransport;importcom.google.api.client.json.gson.GsonFactory;importcom.google.api.services.drive.Drive;importcom.google.api.services.drive.model.File;importcom.google.api.services.slides.v1.SlidesScopes;importcom.google.auth.http.HttpCredentialsAdapter;importcom.google.auth.oauth2.GoogleCredentials;importjava.io.IOException;importjava.util.Collections;/* Class to demonstrate the use of Slides Copy Presentation API */publicclassCopyPresentation{/** * Copy an existing presentation. * * @param presentationId - id of the presentation. * @param copyTitle - New title of the presentation. * @return presentation id * @throws IOException - if credentials file not found. */publicstaticStringcopyPresentation(StringpresentationId,StringcopyTitle)throwsIOException{/* Load pre-authorized user credentials from the environment. TODO(developer) - See https://developers.google.com/identity for guides on implementing OAuth2 for your application. */GoogleCredentialscredentials=GoogleCredentials.getApplicationDefault().createScoped(Collections.singleton(SlidesScopes.DRIVE));HttpRequestInitializerrequestInitializer=newHttpCredentialsAdapter(credentials);// Create the drive API clientDrivedriveService=newDrive.Builder(newNetHttpTransport(),GsonFactory.getDefaultInstance(),requestInitializer).setApplicationName("Slides samples").build();StringpresentationCopyId=null;try{// Copies an existing presentation using specified presentation title.FilecopyMetadata=newFile().setName(copyTitle);FilepresentationCopyFile=driveService.files().copy(presentationId,copyMetadata).execute();presentationCopyId=presentationCopyFile.getId();// Prints the new copied presentation id.System.out.println("New copied presentation id "+presentationCopyId);}catch(GoogleJsonResponseExceptione){// TODO(developer) - handle error appropriatelyGoogleJsonErrorerror=e.getDetails();if(error.getCode()==404){System.out.printf("Presentation not found with id '%s'.\n",presentationId);}else{throwe;}}returnpresentationCopyId;}}
functioncopyPresentation(presentationId,copyTitle,callback){constrequest={name:copyTitle,};try{gapi.client.drive.files.copy({fileId:presentationId,resource:request,}).then((driveResponse)=>{constpresentationCopyId=driveResponse.result.id;if(callback)callback(presentationCopyId);console.log('create copy_presentation with id',presentationCopyId);});}catch(err){document.getElementById('content').innerText=err.message;return;}}
/** * Copys a Google Slide presentation. * @param {string} presentationId The presentation to copy. * @param {string} copyTitle The new title. */asyncfunctioncopyPresentation(presentationId,copyTitle){const{GoogleAuth}=require('google-auth-library');const{google}=require('googleapis');constauth=newGoogleAuth({scopes:'https://www.googleapis.com/auth/drive',});constservice=google.drive({version:'v2',auth});constrequest={name:copyTitle,};try{constdriveResponse=awaitservice.files.copy({fileId:presentationId,resource:request,});constpresentationCopyId=driveResponse.data.id;console.log('Created copied presentation with ID: '+presentationCopyId);returndriveResponse;}catch(err){// TODO (developer) - handle exceptionthrowerr;}}
importgoogle.authfromgoogleapiclient.discoveryimportbuildfromgoogleapiclient.errorsimportHttpErrordefcopy_presentation(presentation_id,copy_title):""" Creates the copy 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. """creds,_=google.auth.default()# pylint: disable=maybe-no-membertry:drive_service=build("drive","v3",credentials=creds)body={"name":copy_title}drive_response=(drive_service.files().copy(fileId=presentation_id,body=body).execute())presentation_copy_id=drive_response.get("id")exceptHttpErroraserror:print(f"An error occurred: {error}")print("Presentations not copied")returnerrorreturnpresentation_copy_id
تاريخ التعديل الأخير: 2024-12-21 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2024-12-21 (حسب التوقيت العالمي المتفَّق عليه)"],[[["This page explains how to create new Google Slides presentations and copy existing ones programmatically."],["Creating presentations involves using the Slides API's `presentations.create` method to generate a blank presentation with a specified title."],["Copying presentations leverages the Drive API's `files.copy` method to duplicate an existing presentation, allowing for a new title."],["Presentations are saved to the user's root Drive folder by default, but can be moved or created in specific folders using the Drive API."]]],["This content outlines two primary actions: creating and copying presentations using Google Slides API. To create, the `presentations.create` method is used, generating a blank presentation with a specified title. To copy, the `files().copy` method from the Drive API is employed, requiring a source presentation ID and a new title. By default presentations are created in the users root folder, but the document explains how they can be moved or created in a specific folder using the Drive API. Code samples are provided in various languages.\n"]]