I'm constantly getting an "Access Not Configured" error despite having done everything the tutorial page has instructed.
Help!
There is a missing step in the tutorial.
Where it says:
Section 1: Activate the Google BigQuery service in Apps Script
Create a new spreadsheet.
Click Tools > Script Editor... to open the script editor.
Click Resources > Use Google APIs....
Enable the BigQuery API (v2), then click OK (no API Key is required).
It's missing step 5 and 6:
Click on "To use the selected APIs, enable them in the Google APIs Console."
Turn on "BigQuery API."
First Configured it on Google API Console
1. Go to Google API Console
2. Create New Project
3. In Services Tab Enabled a BigQuery API
then you can configured in Apps script steps that you followed
Related
Where do I even begin... (Google, why must you hurt me this way?)
Background Info
I have created a new chatbot using Google Apps Script, which receives messages from users in Google Chat and responds synchronously with a single message (each message can only have one response from the chatbot).
Now I need a way to send asynchronous messages so that the bot can send messages on its own, or send multiple separate responses at a time.
The problem
The Google Chat REST API has a method to create a message asynchronously, but this method (spaces.messages.create) does not work! There are no working examples of this method from 2020.
Here is Google's example code for creating a message using the REST API.
The problem is that in their example, the SCOPE is set to a URL that no longer exits:
var SCOPE = 'https://www.googleapis.com/auth/chat.bot';
If you navigate to that URL, you will see this 404 error:
Not Found
Error 404
Furthermore, if you check the list of available OAuth2 scopes, you will notice that there are no scopes related to Hangouts or Chat, and there is no mention of the chat.bot the scope which was used in the example code.
What have I tried?
I have read through every question on StackOverflow that is related to this Chat API, plus every tutorial for the REST API.
The official Apps Script tutorial from Google does not work because the chat.bot scope no longer exists:
Async Messages using Apps Script
These StackOverflow solutions all make use of the same non-existant chat.bot scope:
Send private message without event
Asynchronously Respond in new Hangout Chat using rest API
404 truncated server response on Apps Script Bot
This StackOverflow user says they were able to use the chat scope (i.e. googleapis.com/auth/chat), but that scope does not exist either:
Error 400: invalid_scope
In conclusion
How to send messages from Google Apps Script to Google Chat using the Google Chat REST API?
It seems that Google's documentation is outdated, and none of the examples for this API work as of August 2020. They are either unaware that their REST API does not work, or they deprecated the REST API without telling anyone.
Answer:
I can confirm that the chat.bot scope does indeed exist. To set up a chat bot with the REST API, you must use a service account.
More Information:
As per the documentation you linked on Developing bots with Apps Script, for sending async messages on trigger:
...the only way to achieve this currently is via the external HTTP API (see documentation). This requires the use of a Cloud service account (see documentation) via the OAuth2 for Apps Script library.
This means, that you must first set up a service account in the GCP console so that the chat.bot scope can be used for these messages. The whole process can be quite arduous for the unintitiated, so I will provide the steps from start to finish here.
The Process:
Creating a Service Account:
Navigate to the Google Cloud Console and create a new GCP Project. Hit Select a project at the top of the page and click NEW PROJECT.
You will need to provide a Project name, the other fields should be filled out for you automatically.
Press CREATE - a new pop-up will appear in the top-right of the screen confirming that a new project is being created. Once loaded, you can click VIEW.
Click the ☰ icon in the top-left, and follow the APIs & Services > Credentials menu item.
At the top of this page, click + CREATE CREDENTIALS > Service Account.
Give the service account a name and a description, and press CREATE, followed by CONTINUE, and finally DONE.
Your service account has now been created.
Creating Service Account Credentials:
These will be needed for the code provided in the example from the Developing bots with Apps Script page.
After creating the Service Account, you will be redirected back to the list of Credentials you can use for the GCP Project. Under the Service Accounts section, click you newly-created service account. This will be called service-account-name#project-name-XXXXXX.iam.gserviceaccount.com
Click ADD KEY > Create new key
Keep JSON selected, and press CREATE.
This will initiate a download of a credentials file which you will need to use to access the API as this service account. DO NOT LOSE OR SHARE THIS FILE. If lost, you will need to delete and create new credentials for this account.
Enabling the Hangouts Chat API:
Going back to ☰ > APIs & Services, and select Library.
Search for Hangouts Chat API and click the only result.
Click ENABLE. This will enable the API for your project.
Note: Do not close this tab yet! We will still need to use the GCP console later.
Setting up the Apps Script Project:
Create a new Apps Script project.
Now, you can copy + paste the example from the Async messages page into the new project.
Open up that credentials file that you downloaded from the GCP console.
Copy the private_key value (the one that starts with -----BEGIN PRIVATE KEY----- and paste it into value of SERVICE_ACCOUNT_PRIVATE_KEY in the Apps Script project.
Also copy the client_email value from the credentials file, and paste it into the SERVICE_ACCOUNT_EMAIL in the Apps Script project.
In order to use the Google Apps Script OAuth2 library as in the example, you will need to add the library to the project using the library's script ID.
In the Apps Script project UI, follow the Resources > Libraries... menu item, and copy paste the OAuth2 script ID into the Add a library box
The script ID is 1B7FSrk5Zi6L1rSxxTDgDEUsPzlukDsi4KGuTMorsTQHhGBzBkMun4iDF
This, and the rest of the library can be found on the the OAuth2 for Apps Script GitHub repository
Make sure to select the latest stable version of the library (at time of writing, this is version 38)
Press Save.
Next, you will need to link the Apps Script project to the GCP project you created earlier.
Go back to the GCP Console tab, and follow the ☰ > IAM & Admin > Settings menu item.
Copy the Project number defined on this page.
In your Apps Script Project, follow the Resources > Cloud Platform project... menu item, and paste the Project number into the Enter Project Number here dialog.
Click Set Project.
Setting up the Project Manifest:
In order to use a chat bot in Apps Script, you must include the chat key in the project's manifest.
In the Apps Script UI, click View > Show manifest file.
After the last key-value pair, add the following:
"chat": {
"addToSpaceFallbackMessage": "Thank you for adding me!"
}
Your full manifest file will now look something like this:
{
"timeZone": "Europe/Paris",
"dependencies": {
"enabledAdvancedServices": [{
"userSymbol": "Drive",
"serviceId": "drive",
"version": "v2"
}],
"libraries": [{
"userSymbol": "OAuth2",
"libraryId": "1B7FSrk5Zi6L1rSxxTDgDEUsPzlukDsi4KGuTMorsTQHhGBzBkMun4iDF",
"version": "38"
}]
},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8",
"chat": {
"addToSpaceFallbackMessage": "Thank you for adding me!"
}
}
Save your project.
Final Steps:
You're nearly done! Now, you will need to deply the bot from manifest, and set up the configuration in GCP and set up the trigger which will make the actual call.
Deploying the bot:
In the Apps Script UI, go to Publish > Deploy from manifest... and hit Create in the newly opened dialog.
Note: You can not use the Head deployment if you want to use this for your whole domain, so a new deployment must be created.
Give the deployment a name and description, and press Save.
Once this has finished saving, press Get ID next to the deployment you just created, and copy the Deployment ID.
Setting up GCP configuration:
Going back to the Cloud console, you will need to now navigate to ☰ > APIs & Services > Dashboard.
In the list of enabled APIs at the bottom of this page, select the Hangouts Chat API.
On the left menu, select Configuration.
Set up your bot configuration. You will need to provide a Bot name, Avatar URL, and Description. Set up the functionality settings so that it works in rooms.
Under Connection Settings, select Apps Script project, and paste in your deployment ID from the previous section.
Give your Apps Script bot the relevant permissions, and press Save.
The Elusive Trigger:
The only thing you now need to do is set up your trigger. This is done like a normal Apps Script trigger - from the Edit > Current project's triggers menu item in Apps Script. To complete the example, click the + Add Trigger button in the bottom right and set up the trigger settings as follows:
Choose which function to run: onTrigger
Choose which deployment should run: Head
Select event source: Time-driven
Select type of time based trigger: Minutes timer
Select minute interval: Every minute
And press save.
And you're done! This created bot will now post to all rooms that it is in the current time, every minute.
References:
Service accounts | Cloud IAM Documentation
Understanding service accounts | Cloud IAM Documentation
Developing bots with Apps Script | Google Chat API | Google Developers
Bot-initiated messages - Creating new bots | Google Chat API | Google Developers
GitHub - gsuitedevs/apps-script-oauth2: An OAuth2 library for Google Apps Script.
Google Cloud Console
Whenever I run the following function
function getDatabases(){
var files = DriveApp.getFilesByType(MimeType.GOOGLE_SHEETS);
var amount = 0;
while (files.hasNext()){
if((files.next().getName()).indexOf("Database") > -1){
amount++;
}
}
return amount;
}
I get this error:
This suddenly started about a month and a half ago. The same code was working earlier so I thought I reached a quota limit but that was not the case.
got my solution
In the script -> Resources -> Advanced google services -> turn on Drive API
Click in below message " Google Cloud Platform API Dashboard" to open de cloud project for the script. With the project selected, search in the search bar "Drive API" -> ENABLE, do the same for "Google Drive API".
Done, no more "we're are sorry server error" for DriveApp functions in the script.
Also: I enabled other APIs and advanced services Drive Activity API, just in case...
I ran into this issue too...
Like Nicolás Paulino mentioned, check your "Advanced Google Services" are turned on with the Apps Script Editor UI..
As stated...from the apps script editor..
select the "Resources" menu item
then "Advanced Google Services"
then find all/all related services and toggle them on.
Then head to ...
https://console.cloud.google.com/apis/library?project={yourProjectId}
Click on the menu (top-left)
hover on "Apis & Services"
click "Library"
search for any/all related APIs you're using
I've just had your same issue and it took me forever to fix it. What worked for me was to create a copy of the spreadsheet with the bound script. After authorising everything again in the copy, it worked. Hope it helps!
If you have connected your Apps script to Google Cloud Project then you have to enable the Drive API in your console.
Drive API: https://console.cloud.google.com/apis/api/drive.googleapis.com/
Else you can go to Apps script -> Services -> Add Drive API
Source: https://developers.google.com/apps-script/guides/services/advanced
Also beware that there is a quota limit for the number of times you have called the DriveAPI. If you are not connected to any GCP project then just create a new copy of spreadsheet and try again.
Whenever I run the following function
function getDatabases(){
var files = DriveApp.getFilesByType(MimeType.GOOGLE_SHEETS);
var amount = 0;
while (files.hasNext()){
if((files.next().getName()).indexOf("Database") > -1){
amount++;
}
}
return amount;
}
I get this error:
This suddenly started about a month and a half ago. The same code was working earlier so I thought I reached a quota limit but that was not the case.
got my solution
In the script -> Resources -> Advanced google services -> turn on Drive API
Click in below message " Google Cloud Platform API Dashboard" to open de cloud project for the script. With the project selected, search in the search bar "Drive API" -> ENABLE, do the same for "Google Drive API".
Done, no more "we're are sorry server error" for DriveApp functions in the script.
Also: I enabled other APIs and advanced services Drive Activity API, just in case...
I ran into this issue too...
Like Nicolás Paulino mentioned, check your "Advanced Google Services" are turned on with the Apps Script Editor UI..
As stated...from the apps script editor..
select the "Resources" menu item
then "Advanced Google Services"
then find all/all related services and toggle them on.
Then head to ...
https://console.cloud.google.com/apis/library?project={yourProjectId}
Click on the menu (top-left)
hover on "Apis & Services"
click "Library"
search for any/all related APIs you're using
I've just had your same issue and it took me forever to fix it. What worked for me was to create a copy of the spreadsheet with the bound script. After authorising everything again in the copy, it worked. Hope it helps!
If you have connected your Apps script to Google Cloud Project then you have to enable the Drive API in your console.
Drive API: https://console.cloud.google.com/apis/api/drive.googleapis.com/
Else you can go to Apps script -> Services -> Add Drive API
Source: https://developers.google.com/apps-script/guides/services/advanced
Also beware that there is a quota limit for the number of times you have called the DriveAPI. If you are not connected to any GCP project then just create a new copy of spreadsheet and try again.
I'm trying to use the real-time-data export for google analytics in google sheets scripts.
However my google analytics api/ developer console is under a different account as my google sheets account.
I specify the project my google sheets script should use in the following line:
var ana = Analytics.Data.Realtime.get('ga:xxxxxxxxx','rt:activeUsers, rt:source', {'dimensions' : 'rt:source,rt:medium'});
However this throws the error:
Access Not Configured. Google Analytics API has not been used in project 1046300490979 before or it is disabled.
When i open up this error and click the link provided it sends me to a different project then the project id i specify in the line of code above.
How would i go about getting google analytics data through the API of a different account?
P.S.: I have followed the following guide to set up my google sheets script: https://www.tatvic.com/blog/google-analytics-real-time-data-in-google-sheet/
EDIT: I found out that you can change the project connected to your script.
However after doing so i am getting the following error:
User does not have sufficient permissions for this profile. (regel 3, bestand 'Code')
In the developer console i have access to everything.
Turns out i was using the wrong id's so i'll elaborate a little on where to get what id's in the tutorial above.
Under Resources -> Cloud Platform-project you have to link your script to your google developer console.
You can find this id by going to your developer console, selecting the project connected to your google analytics account. There should be a projectID under Projectinformation
In the following line:
var ana = Analytics.Data.Realtime.get('ga:xxxxxxx', 'rt:activeUsers', {'dimensions' : 'rt:source,rt:medium'});
xxxxxxx should be replaced by your google analytics project id, open your google analytics and look at the URL it should be all numbers behind the p.
https://analytics.google.com/analytics/web/#/report-home/a75228945w113577272p128654983
I am trying to publish a spreadsheet web add-on but getting following error.
There is no API Console project with the id specified in the
manifest's api_console_project_id field
Can anyone tell me why I am getting this error ?
Gosh... not sure why this was so hard.
If Google are reading this: it'd be more user-friendly to run the various API checks before the user selects to publish their add-on and/or provide a link to the correct documentation! Then fix that super cryptic error message.
Anyway, if you are stuck with this error, this is what you need to do. (Thanks Tanya Gupta for putting me on the right track).
Step 1: Enable the GSuite Marketplace SDK
Follow these steps:
From the Script Editor, open the Resources menu item then select Cloud Platform Project
Click the button View API Console (you can also click the link with your project ID)
Click the hamburger (navigation) icon on the top left and select "APIs & Services" then "Library"
Search for "GSuite Marketplace SDK". It's important you install the SDK (software development kit) not the API.
Click the ENABLE button
You should now be able to see an option for Configuration in the menu on the left.
Step 2: Configure the GSuite Marketplace SDK
For configuration you will need to:
select at least one language and enter an application description (for your add-on). The name should be pre-filled and match your script name.
upload some icons of various sizes
add a Terms of Service URL (I initially used a public Google Doc for my T&Cs but this would not pass the new OAuth client requirements which require a verified domain. If you don't have a verified domain then users will see a security warning when installing your add-on. You - apparently - can use Github pages but please don't quote me on that.)
enable at least one Add-on extension
When you enable the Add-on extension, you will need to provide the following information:
Add-on Script Project Key can be found from the Script Editor. Go to File > Project Properties and copy the value for Project key (Deprecated)
Add-on Script Version is the version of your script. You can find the version in the Script Editor. Go to File > Manage Versions and select the latest version of your script.
Note: your add-on script version will be updated automatically when you publish new releases of your add-on.
Google documentation:
https://developers.google.com/gsuite/add-ons/how-tos/publish-for-domains#before_you_publish
Just to build on Dagmar's Answer
Solve this issue in 8 steps with Pictures:
On Apps Script Menu Bar, go to Resources > Cloud Platform project...
On Google Cloud Platform, go to the left navigation menu Select APIs & Services > Library
In the search bar that appears, type in "GSuite Marketplace SDK" Hit Search, once it appears click it.
Click on "ENABLE"
Once you click Enable in step 4. the screen below should appear. Select "CONFIGURATION"
Fill the document as you deem fit, but the most important part is shown below.
Scroll Down to Editor Add-on extensions, then select the Google App you're building your add-on for. It's the same process for Docs, Forms Sheets or Slides Add-ons
How to Get Script Project Key. Go back to your Apps Script Page.
Go to File > Project properties. Select the 'Info' tab. Then copy the value of Project key (Deprecated) and paste into the "Script Project Key" field
How to Get Script Version. Still on your Apps Script Page.
Go to File > Manage versions....
Then copy the value of Version and paste into the "Script Version" field
Click Save Changes and voila you're done. Do not forget to add the privacy policy URL and other required info, else the changes will not be saved
If you are publishing on Google Apps Marketplace, you need to not only enable the API, you also need to configure it by entering the needed settings.
1) First click on the enabled API as per image below:
2) Then click on configuration.
3) Then fill out the values as per below:
4) Particularly important are (not shown here):
a) including correct oauth scopes (File->Project Prop->Scope from your script file)
b) Docs Add On Project Key (File->Project Properties->Info->Project key)
c) Docs Add On Script Version (from the developer console)
Now if you go back and publish you should no longer have the error