google-apps-script | Google Apps Script
kandi X-RAY | google-apps-script Summary
kandi X-RAY | google-apps-script Summary
Google Apps Script
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of google-apps-script
google-apps-script Key Features
google-apps-script Examples and Code Snippets
Community Discussions
Trending Discussions on google-apps-script
QUESTION
I want to create a Google script to check if a given URL is indexed by Google, so I write the following function:
...ANSWER
Answered 2021-Jun-15 at 06:28Unfortunately doing this directly by attempting to web scrape the search results using UrlFetchApp will not work. You can use third party tools to get the number of search results, however.
More Information:I tested this out using an exponential backoff method which sometimes is able to get past 429
errors when a fetch request is invoked by UrlFetchApp
.
When using UrlFetchApp
to either web scrape or to connect to an API, it can happen that the server denies the request on the grounds of too many requests
- or HTTP Error 429
.
Google Apps Script runs in the cloud, from a set of IP addresses in a pool that Google own. You can actually see all the IP ranges here. Most websites (especially large companies such as Google) have architecture in place to prevent the use of bots scraping their websites and slowing down traffic.
Sometimes it's possible to get past this error, using a mixture of exponential backoff and random time intervals as shown for the Binance API (Full Disclosure: this GitHub repository was written by me.)
I assume that either Google directly blocks the Apps Script IP pool, or there are simply too many people trying the same thing - because with the same techniques I was unable to get any response that didn't involve entering a captcha as we discussed in the comments above and can be seen in the log of the page
string.
There are many third party APIs that you can use to do this, and I suggest searching for one that meets your needs.
I tested out one called Authoritas which returns search engine indexing for different keywords. The API is asynchornous, so can take up to a minute to get a response, so a Web App solution needs to be made.
The flow I used is as follows:
- Obtain API key from Authoritas (free)
- Create a new Apps Script project to make an API call:
QUESTION
I saw this post about Google Apps Script - Copy row from table if value in table meets condition. Is there any way to do the same with gsheet formula and not apps script?
...ANSWER
Answered 2021-Jun-05 at 00:34You can try with QUERY
or FILTER
approach.
=query({A2:C5}, "select * where Col1='A'")
=filter(A2:C5, A2:A5 = "A")
- I recommend using filter if data is simpler and can be written as a single range.
- I recommend using query for complicated/composite data via combining columns coming from different sheets, or columns not beside each other and needs to be put into array (e.g.
{A1:A, C1:C}, etc.
)
QUESTION
- I want to create PDF files per each slide of a Google slide file (a normal slide with words and graphs).
- I reviewed past questions and I found a solution that generates PDF files but taking the slides as images (I need to be able to search for words in those pdf).
- Another solution was applied to convert the spreadsheet -> PDF but also it didn't work for my case.
ANSWER
Answered 2021-May-18 at 08:18I believe your goal as follows.
- You want to export each page of a Google Slides as each PDF file.
- You want to achieve this using Google Apps Script.
In this case, how about the following flow?
- Retrieve all slides from the source Google Slides.
- Create a temporal Google Slides.
- Export each page as a PDF file.
- Remove the temporal Google Slides.
When this flow is reflected to a script, it becomes as follows.
Sample script:Please copy and paste the following script to the script editor of Google Slides, and run the function myFunction
. By this, the script is run.
QUESTION
My Google Application Script creates PDF file. The I want to let user to download it. I wanted to make it easier for every one so I thought web application would be great choice. So I started to google for solution but I was not able to find anything userful.
Ideally I want to have form where web user enters a code that triggers PDF file creation (that part is ready - the PDF sits in Google Drive) and then the file is downloaded to end user computer via web browser.
Is that possible via web created in Google Application Script?
From this answer I found that what I am looking for is not possible https://stackoverflow.com/a/36701196/250422
The closest solution I found is google-web-app-script-to-auto-download-from-google-drive
...ANSWER
Answered 2021-May-15 at 12:15I believe your goal as follows.
- You want to make users download a PDF file with the user's browser.
- You want to achieve this using Web Apps created by Google Apps Script.
In this case, how about the following sample script? In this sample script, the PDF file is converted to the data URL, and it makes users download as a PDF file using the browser.
Sample script: Google Apps Script side:Code.gs
Please copy and paste the following script to the script editor as Code.gs
. And, please set the file ID of the PDF file. And, please deploy Web Apps.
QUESTION
I have taken the script from this post Which works perfectly when exporting to a folder in "My Drive" but if I try exporting it to folder in a "Shared drive" I get this error:
GoogleJsonResponseException: API call to drive.files.insert failed with error: File not found: 1ENj9R......
Is there any way around this?
...ANSWER
Answered 2021-May-09 at 03:43In your situation, please include supportsAllDrives
to the query parameter. When the script in this thread is modified, it becomes as follows.
QUESTION
In my Apps Script add-on, I need to use an external library JSSoup for managing some HTML text. I followed this answer to figure out how to add/import an external library in Apps Script. Then I added eval(UrlFetchApp.fetch('https://github.com/chishui/JSSoup/blob/master/lib/jssoup.js').getContentText();
in my script but it is throwing this error:
ANSWER
Answered 2021-May-06 at 16:12Upon checking the fetched content, it shows the all the page content rather than just the code. It is because you are getting all the content of that page, not just the code. Use the raw version instead by clicking the Raw
icon and should redirect you to the correct link.
eval(UrlFetchApp.fetch('https://raw.githubusercontent.com/chishui/JSSoup/master/lib/jssoup.js').getContentText());
- Although after getting the proper content, you will encounter another issue. For that, you might need to post another question here for others to answer that issue.
QUESTION
I'm looking for a way to trigger a GAS (google app script) when I upload a file to google drive. I was pointed to the push notification API. I can't get it to work with GAS. There are a lot of questions about this on StackOverflow, but they were all 5+ years ago. Any change since then? Can I do this without using cloud functions?
Questions I've looked through:
- Can I trigger a Google Script when a file is saved to Google Drive? (No Real Solution)
- Creating a Google Apps Script which Automatically Executes on Upload (No Answer)
- Drive API Push Notifications for a Google Apps Script Web App (Possible Solution?)
- Use a GAS published web app as a handler for Drive push notifications (Not Helpful)
- Unable to create subscription with a push end point on App Script (script.google.com) (Outdated)
- Use Google Script's Web App as Webhook to receive Push Notification directly (Outdated & Not Helpful)
And much more I've not mentioned here.
I am also aware you can do this with a timer, but waiting 15 minutes for the change to take effect would hurt my use by quite a bit. One mentions a solution I like, but I don't know how to make it work :
UPDATE: Gmail leverages Cloud Pubsub for push notifications and this service has recently been updated to remove the need for domain verification for push endpoints. So, going forward its now possible to use GAS Web App URLs in this scenario.
If I could make it work it would solve my issue. Question about the above: Google Push Notifications API Without domain Using App Script
...ANSWER
Answered 2021-Apr-28 at 11:48The Gmail API uses Cloud Pubsub to send push notifications.
Unfortunately, the Drive API does not currently have that capability. The Drive API leverages HTTP endpoints (aka. webhooks) to receive push notifications and that requires domain verification (see documentation).
In the past, GAS Web Apps were automatically verified when registered with the Chrome Web Store, but that option was removed from the IDE back in 2019.
Moreover, the Drive API sends most of its notification payload as HTTP headers which cannot be accessed from a GAS Web App (doPost(e)
only allows access to the POST body and URL params).
So what you want is not currently possible using GAS, at least not by itself. If you want to remain within Google's ecosystem, you can try using a GCP Cloud Function instead (or maybe as an intermediary service), but its not free.
Alternatively, you can setup an endpoint outside of Google's platform (for example; a URL to a PHP script hosted on your own domain), but you'll need to verify that endpoint's URL using one of the methods outlined in the documentation.
QUESTION
I'm pretty much trying to copy the conditional formatting that I put to notify users of "bad" data, but with script to prevent sending bad data and giving unique error messages. With the answer from my last question, the checks and preventing sending no data or data with duplicates works, but I'm now stuck on preventing sending of data that does not match the format of a four digit number.
My conditional formatting was to set the background color to orange on anything that was not equal to or in between 1000 and 9999, but I'm having trouble getting the scripting to work--I'm trying to use negation of anything in between those two values as the "false" that will prompt an error message, and the "true" to let the rest of the script run that will send the data and notification emails out. However, this makes it say that there are bad values even if I do have the correct data in. Removing the negation lets anything go through, like it's not actually checking it. Any ideas?
The section I'm asking about is the last else if statement:
...ANSWER
Answered 2021-Apr-27 at 23:17As far as I can tell in the function sendDataAndTimestamp2()
you need to get rid of empty values from data
. It can be done with filter(String)
method:
QUESTION
I'm trying to include a duplicate check in a script that uses a Google Sheet as an input form for data that sends it to another spreadsheet. I'm trying to set up the check to prevent sending if there are duplicates present or no data, but I keep getting the message saying that there are duplicates even if there are not, or even if there are no values. Any idea on what is going wrong?
Sources of some of my script: https://techyesplease.com/code/google-apps-script-find-duplicates-sheets/
https://www.freecodecamp.org/news/check-if-javascript-array-is-empty-or-not-with-length/
https://amarindaz.com/google-apps-script-if-else-statements/
...ANSWER
Answered 2021-Apr-20 at 12:26It is finding duplicates because you are retrieving several empty cells, and two empty strings are duplicates from each other.
Solution:At readData
, you are providing lastRow
as the third parameter of getRange(row, column, numRows). This refers to the number of rows in your range. Since the first row is 6, the last 6 rows in the retrieved range will be empty cells. You can fix that by making your third parameter var numRows = lastRow - firstRow + 1
instead.
Also, in order to make sure you have no empty cells in the column, you can remove them from your array via filter(String)
(see filter).
Also, I'd suggest using flat() in order to get a 1D array, instead of the more complicated concat
and apply
process you're using.
QUESTION
I have been trying to make a Google Sheet for some purpose which shall have details of various movies. Here is the link: https://docs.google.com/spreadsheets/d/10-4BWaK-zmTxmqr2ov7AvjQW-wAFR8NKXkICuCK1dTY/edit?usp=sharing
Now I have different sheets for different years as visible in the sheet. Now in the column Platform
I want to expand the drop down. Obviously it will be time consuming if I edit every sheet individually. I also have another sheet with name Platforms
which lists all option required in drop down of all sheets. So I there anyway that the drop down list is dependent on the data in sheet Platforms
.
google-apps-script
ANSWER
Answered 2021-Apr-13 at 11:12Just go to data -> data validation and choose the "list from range" option then select the range you want in the "platforms" sheet.
Reference:Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install google-apps-script
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page