- Open Script Editor. And please operate follows by click.
- Resource -> Library
- Input Script ID to text box. Script ID is
1l_XfWeEKp-g45lI-ikQ1KFrHX9YWlR2rWpaVMVs8miaa3J6PUYQqDo5C
. - Add library
- Please select latest version
- Developer mode ON (If you don't want to use latest version, please select others.)
- Identifier is "
ProjectApp
". This is set under the default.
If you want to read about Libraries, please check this..
- Open script editor.
- Open Resources -> Cloud Platform project
- Click the link below "This script is currently associated with project:".
- At Google Cloud Platform
- Click Enable APIs and get credentials like keys at Getting Started.
- Click Credentials at the left side.
- Select OAuth client ID from Create credentials.
- Select Web Application.
- Please input Name. You can freely give it by yourself.
- "Authorized JavaScript origins" is not required to be inputted.
- In current stage, "Authorized redirect URIs" is not required to be inputted yet.
- Click Create button.
- Copy client ID and client secret.
- After copied them, click OK button.
At this time, please don't close "Google Cloud Platform". For the created credential with client ID and client secret, "Authorized redirect URIs" retrieved at a next step is required to be added.
- Please copy and paste the following script to the script editor installed the library. After copied and pasted it, input client ID and client secret which were retrieved above step. And push save button on the script editor.
function doGet(e) {
var Properties = PropertiesService.getScriptProperties();
var pa = ProjectApp.init(Properties);
pa.setProp(
"", // <--- Input client_id
"" // <--- Input client_secret
);
return pa.getAccesstoken(e);
}
- Deploy and launch Web Apps for retrieving redirect uri. The detail information is here.
- On the Script Editor
- Publish -> Deploy as Web App
- Please input project version. You can freely give it by yourself.
- At Execute the app as, select "Me (your account)"
- At Who has access to the app, select "Only myself"
- Click "Deploy"
- When clicked "Deploy", if the authorization is required, please do it.
- At "Test web app for your latest code.", click "latest code"
- By this click, it launches the authorization process.
- If an error occurs, please reopen the script editor. For example, if you use spreadsheet bound script, please reopen spreadsheet and open the script editor. After this, click "latest code" again.
- When you see "Please push this button after set redirect_uri to 'https://script.google.com/macros/s/#####/usercallback'", it means that the authorization process works fine.
- Please copy the redirect URI shown in the browser. Redirect URI is like
https://script.google.com/macros/s/#####/usercallback
.- At this time, please don't close this window.
- Please go back to "Google Cloud Platform" which has already opened. Please click the created credential.
- Please input the copied
https://script.google.com/macros/s/#####/usercallback
to "Authorized redirect URIs". - Click save button. And click save button more.
- Please copy the redirect URI shown in the browser. Redirect URI is like
- On the Script Editor
- Please go back to the window with "Please push this button after set redirect_uri to
'https://script.google.com/macros/s/#####/usercallback'
". - Click Get access token button.
- Do authorization.
- If you see "The state token is invalid or has expired. Please try again.", please close window. And click "latest code" again.
- When you see "Retrieving access token and refresh token was succeeded!", please close the window. The access token and refresh token are saved to
ScriptProperties
. The install is completed. You can use ProjectApp.
By adding oauthScopes
to Manifests, you can use access token with the added scopes. But if you want to use some methods (for example, it is SpreadsheetApp.), which is required other scopes, in your script, please add the scopes to Manifests. You can confirm and add such scopes by the following method.
- Back up Manifests (appsscript.json).
- Remove
oauthScopes
from Manifests. - Save the modified Manifests.
- On the script editor.
- File -> Project properties
- Scopes tab.
- Copy scopes shown at Scopes tab.
- Restore the backed-up Manifests.
- Add the scopes you copied to
oauthScopes
. - Save the modified Manifests.