Quickstarts نحوه راهاندازی و اجرای برنامهای را توضیح میدهد که Google Workspace API را فراخوانی میکند.
راهاندازیهای سریع Google Workspace از کتابخانههای سرویس گیرنده API برای رسیدگی به برخی از جزئیات جریان احراز هویت و مجوز استفاده میکنند. توصیه می کنیم از کتابخانه های سرویس گیرنده برای برنامه های خود استفاده کنید. این شروع سریع از یک رویکرد احراز هویت ساده استفاده می کند که برای یک محیط آزمایشی مناسب است. برای یک محیط تولید، توصیه میکنیم قبل از انتخاب اعتبارنامههای دسترسی مناسب برای برنامهتان، درباره احراز هویت و مجوز یاد بگیرید.
یک اسکریپت Google Apps ایجاد کنید که درخواستهایی را به Google Tasks API ارسال میکند.
/** * Lists the user's tasks. * @see https://developers.google.com/tasks/reference/rest/v1/tasklists/list */functionlistTaskLists(){constoptionalArgs={maxResults:10};try{// Returns all the authenticated user's task lists.constresponse=Tasks.Tasklists.list(optionalArgs);consttaskLists=response.items;// Print task list of user if available.if(!taskLists||taskLists.length===0){console.log('Notasklistsfound.');return;}for(consttaskListoftaskLists){console.log('%s(%s)',taskList.title,taskList.id);}}catch(err){// TODO (developer) - Handle exception from Task APIconsole.log('Failedwitherror%s',err.message);}}
روی ذخیره کلیک کنید .
روی پروژه Untitled کلیک کنید، Quickstart را تایپ کنید و روی تغییر نام کلیک کنید.
اسکریپت را پیکربندی کنید
Google Tasks API را فعال کنید
پروژه Apps Script را باز کنید.
روی codeویرایشگر کلیک کنید.
در کنار Services ، روی Add a service add کلیک کنید.
Tasks API را انتخاب کرده و روی Add کلیک کنید.
نمونه را اجرا کنید
در ویرایشگر Apps Script، روی Run کلیک کنید.
اولین باری که نمونه را اجرا میکنید، از شما میخواهد دسترسی را مجاز کنید:
تاریخ آخرین بهروزرسانی 2024-12-21 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2024-12-21 بهوقت ساعت هماهنگ جهانی."],[[["This quickstart demonstrates how to create a Google Apps Script that interacts with the Google Tasks API to list tasks."],["Before running the script, you need a Google account with Google Tasks and Drive enabled, and you will need to enable the Google Tasks API within the script."],["The script utilizes Google API client libraries for authentication and is designed for a testing environment; production environments require more robust authentication."],["After configuring and running the script, it will prompt for authorization to access your Google Tasks data and then display your task lists in the execution log."],["For more advanced usage and troubleshooting, refer to the provided links for Google Apps Script, authentication, and the Tasks API."]]],["This content details how to create and run a Google Apps Script that interacts with the Google Tasks API. Key actions include creating a new script, replacing the default code with a provided sample to list task lists, saving and renaming the script, and enabling the Tasks API within the script's services. Running the script requires authorizing access, after which it will display the user's task lists in the execution log, or error if failed. It use a simplified authorization and suggest to do more in depth authorization for production.\n"]]