How to make gmail remember my Add-on open state? - gmail-addons

I am working on Gmail Add-on using Google Apps Script, it is already published to Gsuite marketplace.
I can see that Gmail is remembering the last open state of google provided add-ons like Calendar, Keep etc, and keep it open even if I refresh / reopen the browser.
But, this is not happening for my add-on.
How can I make Gmail remember my add-on as last opened and open it by default?

You can check out Properties Service to store strings as key-value pairs in apps script.

Related

How can I change the `AUTHORIZE ACCESS` button in a Google Apps Script based Google Workspace Add-On

I am develloping a Google Apps Script based Workspace add-on.
I am trying to figure out how to edit the AUTHORIZE ACCESS button to match Google's Sign-In Branding Guidelines.
I've searched high and low and don't see anything that talks about how to edit the sign-in experience for add-ons.
The branding guidelines apply to buttons that you create yourself.
The AUTHORIZE ACCESS button under the text
Would you like to give this add-on access to your account?
This add-on would like to show additional information in Gmail, but it needs approval to access your Google account.
is a standard Google interface that typically appears when you test an Add-on deploying it from the Apps Script editor
The above mentioned screen cannot be modified in any way, since it is being generated by Google.
In any case, when an Addon is installed from Google Marketplace, opposed to being tested locally, the authorization prompt will occur in a pop-up window during the installation process, rather than within the sidebar of the Add-on.

How to solve the error: Sorry, unable to open the file at this time. Please check the address and try again. (Gmail Add-on)

I have a Gmail Add-on deployed on marketplace, it was working fine but now when a user have multiple accounts logged into gmail and tries to install my add-on. It shows the error
Sorry, unable to open the file at this time.
Please check the address and try again.
The URL of opened popup is (script_id is my project's script id ): https://script.google.com/macros/u/1/s/<script_id>/authorize?scopes=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgmail.addons.current.action.compose%2Chttps%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgmail.addons.current.message.metadata%2Chttps%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgmail.addons.execute%2Chttps%3A%2F%2Fwww.googleapis.com%2Fauth%2Fscript.external_request%2Chttps%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email%2Chttps%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile
When only one account is logged into Gmail, then it works as expected and add-on is installed normally.
I checked other solutions to the same problem, then say we need to remove /u/1/ from the URL. I copy pasted the URL into another tab and removed /u/1/ from the URL. I still got the same error. Also, this URL is generated by Google and not by us, so we cannot edit it.
Any help for the problem mentioned above will be appreciated.
Thanks in advance.
This is a well known issue regarding Apps Script and the way Google handles multiple accounts being logged in.
The documentation states the following regarding this matter:
If you're logged into multiple Google Accounts at the same time, you might have trouble accessing your Apps Script projects, add-ons, and web apps. Multi-login, or being logged into multiple Google Accounts at once, isn't supported for Apps Script, add-ons, or web apps.
Possible workarounds for this include:
Logging out of all your Google Accounts and only log in to the one that has the Apps Script project, add-on, or web app you need to access.
Opening an incognito window in Google Chrome, or an equivalent private browsing window, and log in to the Google Account that has the Apps Script project, add-on, or web app you need to access.
This is currently being tracked on this report here; I suggest you star it as any updates regarding this will be posted there.
Reference
Apps Script Script Projects.

Google Add-on for sheets invalid scope

So following this tutorial I am attempting to extend by adding the add-on via the sidebar. [See the screen shot below] []2
But I am getting this error when attempting to add this auth scope.
Error: invalid_scope
Some requested scopes were invalid. {valid=
[https://www.googleapis.com/auth/gmail.addons.current.message.readonly,
https://www.googleapis.com/auth/script.locale, https://www.googleapis.com/auth/spreadsheets.readonly,
https://www.googleapis.com/auth/gmail.addons.current.action.compose,
https://www.googleapis.com/auth/calendar.addons.execute,
https://www.googleapis.com/auth/drive.addons.metadata.readonly,
https://www.googleapis.com/auth/calendar.readonly,
https://www.googleapis.com/auth/gmail.addons.execute], invalid=
[https://www.googleapis.com/auth/spreadsheets.addons.execute]}
My question is do I need this https://www.googleapis.com/auth/spreadsheets.addons.execute for sheets to see the homepage triggers in my manifest? If not what am I overlooking?
UPDATE
We now have support for Workspace Add-ons in Google Sheets, Google Docs and Google Slides (though it may not be available in all regions as yet)...Google Forms is not yet supported.
What you want to do is not possible as you can only create Editor Add-ons for Google Sheets not GSuite Add-ons.
There are distinct differences between the two.
GSuite Add-ons are currently only applicable to:
Gmail
Google Drive
Google Calendar
Editor Add-ons are currently only applicable to:
Google Sheets
Google Forms
Google Docs
Google Slides
See add-on types documentation for clarification.
Actually you're experiencing this issue because the feature hasn't rolled out yet to your account.
It appears this is a Google Workspace account so you need to navigate to https://admin.google.com/ac/accountsettings/preferences
And select "New Feature"
Then you must select "Rapid Release" and the new Google Workspace add-on feature will be enabled for you probably within 15 minutes but it can take up to 24 hours.
I was experiencing this same issue and once I added this it worked fine.
Also, there isn't an auth scope of https://www.googleapis.com/auth/spreadsheets.addons.execute
You need to simply add https://www.googleapis.com/auth/spreadsheets
and it will work perfectly. Good luck!

Publish an add-on privately

I am trying to publish a test add-on with the option Private, because there is nothing new in this add-on, and would not be accepted by Google if I published it with Public.
The add-on contains a sidebar, a custom menu and a custom function. It works well on its Google Sheet.
In Chrome Web Store, I have added 2 gmails to Edit your tester accounts: under Your developer account. I also created a google group with these 2 gmails.
By following this thread, I did Publish ==> Deploy as Sheets web add-on..., then uploaded different icon and images in Chrome Web Store, paid 5 dollars, left most of boxes blank, then published it with the option Private and chose the created google group.
However, when I open a new Google Sheet with either of these two mails, I cannot find the add-on in Add-ons. By Add-ons ==> Get add-ons..., I cannot find the add-on either.
So does anyone know where this add-on is supposed to appear? Is it because this add-on is under review by Google that it is not available yet.
I am quite surprised to see such a basic publishing is not unclear. Is it because few people publish an add-on with Private?
In your web store dashboard, you should see the link to the add-on. Get the URL for this link and give the URL to the accounts you have created that should have permission. Those accounts need to install the add-on, and then should be able to use it.
I think you can also list your add-on as unlisted and not be required to go through the entire approval process. This makes it a little easier to share your add-ons with specific users.

How to add a Google Apps Script web app as a client in Google API console

I have an app that consists of two parts
an installed application (more specifically: a browser add-on) that runs on the user's machine, and
a web app implemented as a stand-alone Google Apps Script app using HtmlService.
The two parts talk to each other and both access some Google APIs on behalf of the user via Oauth. To do this, I set up an API project in the Google API console. In the section "API Access", I created a client of type "Installed Application" for the browser add-on. For the Apps Script part, Google takes care of the authorization flow automatically.
My problem is that Google does not know that these two clients are part of the same project. Therefore, the user has to go through two authorization steps in a row when executing my app for the first time (first, the Oauth process for the browser add-on and then the automatically generated authorization process from Google Apps Script). This is very confusing to the user, especially, since the splitting between the browser add-on and the web app is rather an implementational detail about which the user shouldn't really have to bother.
Is there a way to unify the two authorization flows? I know that one can add several distinct clients to a single project in the Google API console. It seems to me like this feature is explicitly intended for scenarios similar to mine, where more than one application make up what is perceived as a single service by the user. Unfortunately, web apps that are implemented in Google Apps script don't seem to be compatible with the Google API console because of the way Apps Script generates the authorization flow automatically. Or am I missing an option in the API console or in the Apps Script editor?
For future reference: I found out that Google automatically creates an API project in the Google API console for each Google Apps Script project. This seems to be a fairly recent feature. One difficulty for me was that these API projects don't show up when one goes to the API console, clicks on the name of whatever project is currently opened in the upper left corner and chooses "open". Apparently, the only way to reach the auto-generated API project is as follows:
Go to drive.google.com and open the Google Apps Script project.
Chose "Resources --> Use Google APIs...".
In the popup, click the link to the Google API console.
In principle, this should allow to add additional clients to the project, as long as none of the other clients is also a Google Apps Script project. I haven't been able to test this since it still doesn't solve my specific problem: Sending e-mails from the user's Gmail account seems to be a feature unique to Google Apps Script and I couldn't find an Oauth2 scope for this operation. Therefore, I still cannot ask for all required permissions in a single authorization flow. But if anyone who's reading this has a similar problem with different Oauth2 scopes, the above instructions should fix it for you.
Anyway, I solved my problem in the meantime by no longer using Google Drive to upload files.