क्विकस्टार्ट में, Google Workspace API को कॉल करने वाले ऐप्लिकेशन को सेट अप और चलाने का तरीका बताया गया है. इस क्विकस्टार्ट में, पुष्टि करने का आसान तरीका इस्तेमाल किया गया है. यह टेस्टिंग एनवायरमेंट के लिए सही है. हमारा सुझाव है कि प्रोडक्शन एनवायरमेंट के लिए, ऐक्सेस क्रेडेंशियल चुनने से पहले, पुष्टि करने और अनुमति देने के बारे में जान लें. इससे आपको अपने ऐप्लिकेशन के लिए सही क्रेडेंशियल चुनने में मदद मिलेगी.
Apps Script में, Google Workspace की क्विकस्टार्ट गाइड, Google Workspace API को कॉल करने के लिए Google की ऐडवांस सेवाओं का इस्तेमाल करती हैं. साथ ही, पुष्टि करने और अनुमति देने के फ़्लो की कुछ जानकारी को मैनेज करती हैं.
/** * 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('The presentation contains %s slides:',slides.length);for(leti=0;i < slides.length;i++){console.log('- Slide # %s contains %s elements.',i+1,slides[i].pageElements.length);}}catch(err){// TODO (developer) - Handle Presentation.get() exception from Slides APIconsole.log('Failed to found Presentation with error %s',err.message);}}
सेव करें पर क्लिक करें.
बिना टाइटल वाला प्रोजेक्ट पर क्लिक करें. इसके बाद, Quickstart टाइप करें और नाम बदलें पर क्लिक करें.
स्क्रिप्ट को कॉन्फ़िगर करना
Google Slides API चालू करना
Apps Script प्रोजेक्ट खोलें.
एडिटरcode पर क्लिक करें.
सेवाएं के बगल में, सेवा जोड़ें
add पर क्लिक करें .
Google Slides API चुनें और जोड़ें पर क्लिक करें.
सैंपल चलाना
Apps Script एडिटर में, चलाएं पर क्लिक करें.
पहली बार सैंपल चलाने पर, आपको ऐक्सेस की अनुमति देने के लिए कहा जाएगा:
अनुमतियों की समीक्षा करें पर क्लिक करें.
कोई खाता चुनें.
अनुमति दें पर क्लिक करें.
स्क्रिप्ट के एक्ज़ीक्यूशन का लॉग, विंडो में सबसे नीचे दिखता है.
[null,null,["आखिरी बार 2025-08-29 (UTC) को अपडेट किया गया."],[],[],null,["Create a\n[Google Apps Script](/apps-script/overview)\nthat makes requests to the Google Slides API.\n\nQuickstarts explain how to set up and run an app that calls a\nGoogle Workspace API. This quickstart uses a\nsimplified authentication approach that is appropriate for a testing\nenvironment. For a production environment, we recommend learning about\n[authentication and authorization](/workspace/guides/auth-overview)\nbefore\n[choosing the access credentials](/workspace/guides/create-credentials#choose_the_access_credential_that_is_right_for_you)\nthat are appropriate for your app.\n\nIn Apps Script, Google Workspace\nquickstarts use\n[Advanced Google services](/apps-script/guides/services/advanced) to call\nGoogle Workspace APIs and handle some details of the authentication\nand authorization flow.\n\nObjectives\n\n- Configure the environment.\n- Create and configure the script.\n- Run the script.\n\nPrerequisites\n\n- A Google Account\n\n\u003c!-- --\u003e\n\n- Access to Google Drive\n\nCreate the script\n\n1. Create a new script by going to [script.google.com/create](https://script.google.com/create).\n2. Replace the contents of the script editor with the following code:\n\n\nslides/quickstart/quickstart.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/slides/quickstart/quickstart.gs) \n\n```javascript\n/**\n * Creates a Slides API service object and logs the number of slides and\n * elements in a sample presentation:\n * https://docs.google.com/presentation/d/1EAYk18WDjIG-zp_0vLm3CsfQh_i8eXc67Jo2O9C6Vuc/edit\n */\nfunction logSlidesAndElements() {\n const presentationId = '1EAYk18WDjIG-zp_0vLm3CsfQh_i8eXc67Jo2O9C6Vuc';\n try {\n // Gets the specified presentation using presentationId\n const presentation = Slides.Presentations.get(presentationId);\n const slides = presentation.slides;\n // Print the number of slides and elements in presentation\n console.log('The presentation contains %s slides:', slides.length);\n for ( let i = 0; i \u003c slides.length; i++) {\n console.log('- Slide # %s contains %s elements.', i + 1, slides[i].pageElements.length);\n }\n } catch (err) {\n // TODO (developer) - Handle Presentation.get() exception from Slides API\n console.log('Failed to found Presentation with error %s', err.message);\n }\n}\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n3. Click Save .\n4. Click **Untitled project** , type **Quickstart** , and click **Rename**.\n\n\u003cbr /\u003e\n\nConfigure the script\n\nEnable the Google Slides API\n\nOpen the Apps Script project.\n\n1. Click **Editor** code.\n2. Next to **Services** , click Add a service add .\n3. Select Google Slides API and click **Add**.\n\nRun the sample\n\nIn the Apps Script editor, click **Run**.\n\nThe first time you run the sample, it prompts you to authorize access:\n\n1. Click **Review permissions**.\n2. Choose an account.\n3. Click **Allow**.\n\nThe script's execution log appears at the bottom of the window. \ndone It worked! **Great!** Check out the further reading section below to learn more.\nwarning There was a problem **Bummer** , [let us know what went wrong](#). Check out our [troubleshooting](#troubleshooting) section below for some common errors and solutions. If you have found a bug in the code, [report the issue on GitHub](https://github.com/googleworkspace/apps-script-samples/issues) or submit a pull request.\n\nNext steps\n\n- [Google Apps Script Advanced Services documentation](/apps-script/guides/services/advanced)\n- [Try the Google Workspace APIs in the APIs explorer](/workspace/explore)\n- [Troubleshoot authentication and authorization issues](/workspace/slides/api/troubleshoot-authentication-authorization)\n- [Slides API reference documentation](/workspace/slides/reference/rest)"]]