Przewodniki szybkiego startu wyjaśniają, jak skonfigurować i uruchamiać aplikację, która wywołuje interfejs Google Workspace API.
Szybkie starty Google Workspace korzystają z bibliotek klienta interfejsu API do obsługi niektórych szczegółów procesu uwierzytelniania i autoryzacji. Zalecamy używanie bibliotek klienta w przypadku własnych aplikacji. W tym krótkim wprowadzeniu użyjemy uproszczonego podejścia do uwierzytelniania, które jest odpowiednie dla środowiska testowego. W przypadku środowiska produkcyjnego zalecamy zapoznanie się z informacjami na temat uwierzytelniania i autoryzacji, zanim wybierzesz odpowiednie dla swojej aplikacji poświadczenia dostępu.
Utwórz Google Apps Script, który wysyła żądania do interfejsu API Listy zadań Google.
/** * 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);}}
Kliknij Zapisz .
Kliknij Projekt bez tytułu, wpisz Szybki start i kliknij Zmień nazwę.
Konfigurowanie skryptu
Włącz interfejs Google Tasks API
Otwórz projekt Apps Script.
Kliknij Edytorcode.
Obok opcji Usługi kliknij Dodaj usługęadd .
Wybierz interfejs API Zadania i kliknij Dodaj.
Uruchamianie przykładu
W edytorze Apps Script kliknij Uruchom.
Gdy uruchomisz próbkę po raz pierwszy, pojawi się prośba o autoryzację dostępu:
Kliknij Przejrzyj uprawnienia.
Wybierz konto.
Kliknij Zezwól.
U dołu okna pojawi się dziennik wykonania skryptu.
[null,null,["Ostatnia aktualizacja: 2024-12-21 UTC."],[[["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"]]