Retrieving Access Token for Google APIs
This sample is for retrieving access token for Google APIs. I created this for studying newStateToken().
Preparation
In order to use this sample, please do as follows.
- Deploy and launch Web Apps for retrieving redirect uri
- On the Script Editor
- File
- -> Manage Versions
- -> Save New Version
- Publish
- -> Deploy as Web App
- -> At Execute the app as, select “your account”
- -> At Who has access to the app, select “Only myself”
- -> Click “Deploy”
- -> Click “latest code” (By this click, it launches the authorization process.)
- -> Please copy URL shown in the top of your browser as the redirect URI. And please modify the redirect URI like
https://script.google.com/macros/s/#####/usercallback.
- On the Script Editor
- Open console project
- On the Script Editor
- -> Resources
- -> Cloud Platform Project
- -> Click “Projects currently associated with this script”
- -> Click API in start guide
- On the Script Editor
- Retrieve client id and client secret
- On the Console Project
- Click authentication information at left side
- -> Create a valid Client ID as OAyth client ID
- -> Choose Web Application
- -> Input Name (This is a name you want.)
- -> Input redirect URI that you have already copied.
- -> done
- -> Please copy client ID and client Secret in a pop-up window.
- On the Console Project
Here, you have client ID, client Secret and redirect URI to retrieving refresh token and access token. These can be used for following sample script.