A Complete Guide to Setup GCP for GAS: Guide 003
Introduction
If you are looking for a guide to connect your Google Apps Script project with a Google Cloud Project for some advanced features. For example, publish your project as an add-on in the Google Workspace Market Store, or to enable some Google API Services which are currently not available in Google Apps Script like the Google Blogger API. You can follow this guide.
Instructions (14 Steps)
Follow the steps below to set for your Google Apps Script project.
Step 1
Create a new Google Cloud Project by visiting the link below.
https://console.cloud.google.com/projectcreate
Step 2
Pick a proper name for your project and you can optionally select a location if you are a Google Workspace user, then click the button āCREATEā to continue.
Step 3 (Optional)
If this is your first project, it will be selected by default. And if itās not, you will need to select the new project from the dropdown list.
Step 4
Open the sidebar menu, go to āOAuth consent screenā from āAPIs & Servicesā product.
Step 5
Select the āUser Typeā, āInternalā is for Google Workspace account only, so if you are a free user youāll only have the āExternalā option.
Select āInternalā if the project is used only for your organization. For the Workspace users, you should be aware that once the type is selected, it canāt be changed later. And you have to recreate a new project for the correct type youāll need.
Click the button āCREATEā to continue.
Step 6 - OAuth Consent Screen
If you only need to use the project for yourself or your team and no plan to send your app to Google for review. You only need to fill these 3 required fields, or youāll need to prepare other links, assets for your application.
- App name *
- User support email *
- Email Addresses of developer *
Click the button āSAVE AND CONTINUEā.
Step 7 - Scopes (Optional)
If the app is for your internal use, you donāt need to add any scope here in this step.
If you are publishing your app, Google will need to review the scopes which are used in your app. You should add all the scopes to this section, you should be able to find the scopes in your Google Apps Script manifest file āappsscript.jsonā if you add the scopes manually (This is recommended for publishing an app). If you are not manually adding these scopes for your project, Google will add them for you automatically, and you can find them in the project information.
Make sure the list is fully matched with your project, or Google will reject your project during the review section.
The scopes have 3 types, they will be assigned to one of these categories after added.
- Non-sensitive scopes (Good and easy to go with)
- Sensitive Scopes (Your justification will be required with a YouTube video to explain)
- Restricted Scopes (More requirements will be required than sensitive scopes - donāt use them unless you have to)
Click the button āSAVE AND CONTINUEā to the next section.
Example of scopes manually added into appsscript.json manifest.
Example of scopes added by Google Automatically for your project information.
Step 8 - Test Users
If youāre not planning to publish this project, youāll need to add the users as the test users of your project, so they can use this project. Or they will get an error that says āAppā is blocked by Google when they try to authorize the app.
If youāre publishing your project, make sure all the developers and testers are added to the test users list, or they will not be able to use it before the publication of your app.
In conclusion, any user who needs to use the app before the publish has to be added to this list. Internal apps will never be published, so youāll need to add all your internal users to this list. Please note we have a 100 users limitation.
Click the button āSAVE AND CONTINUEā to the next section.
Step 9 - Summary
Now you have the OAuth consent screen setup and this is a summary of your app. Scroll down and click the button to go back to the dashboard.
Step 10 - Publish App (Optional)
At this stage, the publishing status is āTestingā. If you want to publish your project, click the button āPublish APPā and it will send your app to Google for review.
An automatic email will be sent to you from Google, you will need to review the email and confirm it to start the review process, if Google needs you to provide more information about your app or you have any questions, you can keep communicating there.
And if you need to update your app, like adding a new scope for your app or uploading a new logo of your app. Use the āEDIT APPā button and this will bring you to Step 6 - OAuth consent screen, make the change and resubmit your app for a new review to Google.
If Google approved your app, your app will be āVerifiedā, and the publishing status will be āIn Productionā.
Step 11 - Enable the APIs (Optional)
Open the sidebar menu, and go to āEnabled APIs & Servicesā in the āAPIs & Servicesā product. And click the button ā+ ENABLE APIS AND SERVICESā to continue.
Search for the API you need to add, for example āGoogle Blogger APIā, and enable it by clicking the button āENABLEā. Once itās been added, youāll have access to use this API in your Google Apps Script project.
Step 12
Finally, go back to the dashboard and copy the project number for your Google Apps Script to connect.
Step 13
In your Google Apps Script project settings, paste the project number and set the project, and now you have done all the steps and youāll have the access to use Google Blogger API if you enabled it for the project. And if you need any other Google Services, you just need to update your project.
Step 14 (Optional)
You may have to manually add the scopes in your Google Apps Script project if the scopes canāt be added by Google automatically for you.
For example, we donāt have the Google Blogger API built-in Google Apps Script, to use it in our project, we have to manually add āhttps://www.googleapis.com/auth/bloggerā scope in the list and to use the UrlFetchApp for the API calls we need āhttps://www.googleapis.com/auth/script.external_requestā.
To explain this for beginners, if you have SpreadsheetApp API used in your code, the scope for Google Sheets API āhttps://www.googleapis.com/auth/spreadsheetsā will be added automatically for you and you can find it in the project overview section.
If you canāt see the file āappsscript.jsonā in your project, go to the project settings, and make sure āShow "appsscript.json" manifest file in editorā is checked.
OauthScopes example for using Google Blogger API in the project for Google Sheets.
{
"oauthScopes": [
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/blogger"
]
}
GoogleAppsScript Playlist
Links
Comments
Post a Comment