Quickstarts نحوه راهاندازی و اجرای برنامهای را توضیح میدهد که Google Workspace API را فراخوانی میکند.
راهاندازیهای سریع Google Workspace از کتابخانههای سرویس گیرنده API برای رسیدگی به برخی از جزئیات جریان احراز هویت و مجوز استفاده میکنند. توصیه می کنیم از کتابخانه های سرویس گیرنده برای برنامه های خود استفاده کنید. این شروع سریع از یک رویکرد احراز هویت ساده استفاده می کند که برای یک محیط آزمایشی مناسب است. برای یک محیط تولید، توصیه میکنیم قبل از انتخاب اعتبارنامههای دسترسی مناسب برای برنامهتان، درباره احراز هویت و مجوز یاد بگیرید.
یک اسکریپت Google Apps ایجاد کنید که درخواستهایی را به Google Slides API ارسال میکند.
/** * Creates a Slides API service object and logs the number of slides and * elements in a sample presentation: * https://docs.google.com/presentation/d/1EAYk18WDjIG-zp_0vLm3CsfQh_i8eXc67Jo2O9C6Vuc/edit */functionlogSlidesAndElements(){constpresentationId='1EAYk18WDjIG-zp_0vLm3CsfQh_i8eXc67Jo2O9C6Vuc';try{// Gets the specified presentation using presentationIdconstpresentation=Slides.Presentations.get(presentationId);constslides=presentation.slides;// Print the number of slides and elements in presentationconsole.log('Thepresentationcontains%sslides:',slides.length);for(leti=0;i < slides.length;i++){console.log('-Slide#%scontains%selements.',i+1,slides[i].pageElements.length);}}catch(err){// TODO (developer) - Handle Presentation.get() exception from Slides APIconsole.log('FailedtofoundPresentationwitherror%s',err.message);}}
روی ذخیره کلیک کنید .
روی پروژه Untitled کلیک کنید، Quickstart را تایپ کنید و روی تغییر نام کلیک کنید.
اسکریپت را پیکربندی کنید
Google Slides API را فعال کنید
پروژه Apps Script را باز کنید.
روی codeویرایشگر کلیک کنید.
در کنار Services ، روی Add a service add کلیک کنید.
Google Slides API را انتخاب کنید و روی Add کلیک کنید.
نمونه را اجرا کنید
در ویرایشگر Apps Script، روی Run کلیک کنید.
اولین باری که نمونه را اجرا میکنید، از شما میخواهد دسترسی را مجاز کنید:
تاریخ آخرین بهروزرسانی 2024-12-21 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2024-12-21 بهوقت ساعت هماهنگ جهانی."],[[["This quickstart demonstrates how to use Google Apps Script to create a script that interacts with the Google Slides API."],["You will learn how to configure the script, enable the Google Slides API, and run the script to access slide data."],["The provided code sample retrieves and logs the number of slides and elements within a specific Google Slides presentation."],["To run this quickstart, you'll need a Google Account and access to Google Drive."],["For production environments, review authentication and authorization best practices before choosing access credentials for your application."]]],["This content outlines setting up and running a Google Apps Script that interacts with the Google Slides API. Key actions include creating a new script at script.google.com, pasting provided code into the editor, saving and renaming the project, and enabling the Google Slides API as a service. After this, run the script, authorize access, and view the execution log. The provided code retrieves a presentation by ID, and then prints the number of slides and elements.\n"]]