@@ -6,6 +6,31 @@ expire. This library uses Apps Script's
66[ StateTokenBuilder] ( https://developers.google.com/apps-script/reference/script/state-token-builder )
77and ` /usercallback ` endpoint to handle the redirects.
88
9+ ## Connecting to a Google API
10+
11+ If you are trying to connect to a Google API from Apps Script you might not need
12+ to use this library at all. Apps Script has a number of easy-to-use,
13+ [ built-in services] [ built_in ] , as well as a variety of
14+ [ advanced services] [ advanced ] that wrap existing Google REST APIs.
15+
16+ Even if your API is not covered by either, you can still use Apps Script to
17+ obtain the OAuth2 token for you. Simply
18+ [ edit the script's manifest] [ edit_manifest ] to
19+ [ include the additional scopes] [ additional_scopes ] that your API requires.
20+ When the user authorizes your script they will also be asked to approve those
21+ additional scopes. Then use the method [ ` ScriptApp.getOAuthToken() ` ] [ scriptapp ]
22+ in your code to access the OAuth2 access token the script has acquired and pass
23+ it in the ` Authorization ` header of a ` UrlFetchApp.fetch() ` call.
24+
25+ Visit the sample [ ` NoLibrary ` ] ( samples/NoLibrary ) to see an example of how this
26+ can be done.
27+
28+ [ built_in ] : https://developers.google.com/apps-script/reference/calendar/
29+ [ advanced ] : https://developers.google.com/apps-script/advanced/admin-sdk-directory
30+ [ edit_manifest ] : https://developers.google.com/apps-script/concepts/manifests#editing_a_manifest
31+ [ additional_scopes ] : https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes
32+ [ scriptapp ] : https://developers.google.com/apps-script/reference/script/script-app#getoauthtoken
33+
934## Setup
1035
1136This library is already published as an Apps Script, making it easy to include
0 commit comments