Read Google App Script Files from another script - javascript

I am looking to create a little Google App Script to parse another GAS file to pull out the functions and any jsdoc type comments, and then display it.
Like if you navigate to a script you can get the revision history etc, but I wanted to be able to pass in a Drive folder containing multiple script files and develop a front end to display each's content.
I know about the Google Drive REST API with exportLinks do download as JSON.
I wondered if there was a simpler way to do it from another GAS file, or would I need to URLFetch of some description to do it over the RestAPI?
I have tried searching for similar things but they always lead back to the DriveAPI.
Any help with a starting place, or what GAS Objects I should start looking at?
Thank you

You have to use the REST based Drive API, there is really no other alternative. However, you don't need to use URLFetch to access it. Google Apps Script has what's known as Advance Google Services a collection of interfaces that grant native access to many REST based APIS including the Drive API.
You can check out the Drive specific documentation here. Its somewhat sparse, so you'll often have to fall back on the REST based documentation as well as rely on autocomplete inside the script editor to make sense of things.

Related

Using python to connect or write a google apps script to a google sheet

Is it true that it is not possible to directly connect a Google Apps Script (which uses JavaScript) to a Google Sheets spreadsheet using Python?
I am asking this more as a design question: would it not be possible to keep a Google Apps Script in a file and simply use Python to connect it to a gsheets spreadsheet using the spreadsheet id? I have not found a way to do this, but it would be interesting to hear if anyone has found a way to do it and if so how.
I am not sure if this answer is on topic, but I think it might be what you trying to do... That is, push an apps script file up to Google...
I believe you can accomplish this task via the Apps Script Python API:
https://developers.google.com/apps-script/api/quickstart/python
My company does not give the the creds to use the API, so, I can't give you the step by step on this one...
hth,
David
To be fair, I really don't think this is the right approach. Might depend on what you're doing... If you have a Python script that is writing Google Apps Script and needs to push it to Google, you might look in these docs
https://developers.google.com/apps-script/api/reference/rest
If that's not what you're doing and you're trying to manipulate a Spreadsheet by using Python to run some Google Apps Script, refer to the same link. There is "REST Resource: v1.scripts" which has a "run" method.
Last, if your end goal is to manipulate some Google Sheet--you can probably get away with using a Python library like described in this link
https://developers.google.com/sheets/api/quickstart/python
Because just about anything you can use Google Apps Script for, you can technically also do in Python. Except, with Python you have Python and the entire compendium of Python libraries at your disposal. The Google Sheet is ultimately just a data store and reading and writing to it are the things you're trying to do with it--be it Google Apps Script or Python as the driver.
Otherwise, you might be able to use Python to manipulate CLASP
https://github.com/google/clasp

Should I use both gtag.js and GTM?

I´m a bit confused with Google Tag Manager and gtag.js. I have read a lot about it, but It´s not 100% clear to me what to use in my case.
Historically, we have been using gtag.js in our AngularJS webapp. We also used the library angularytics to track Google Ads conversions of purchases providing dynamically prices and leads directly from our website.
We have migrated to GTM to provide third party libraries from the GTM interface. This means that we have commented/removed gtag.js. Now, we track page analytics from GTM. However, obviously, our angularytics calls to Google Ads conversion tracking using gtag.js has stopped working.
At this poing I´m very confused with some questions:
I have read that I can add Google ads conversion tracking using GTM setting up conversions one by one. But, is it possible to set the price of each product which is totally dynamic? Or this case should I use gtag?
Does GTM provide a library to replace gtag functions? From the SEO optimazation point of view, I think would be interesting to avoid loading two libraries gtm and gtag.
Is there any problem that both libraries live together?
Well, you can think of GTM as a service where you can dynamically change the included tags in a website without direct access to the production source code. This is for example widely used for marketing agencies whose clients won't give away access to their servers. But it doesn't really have anything to do with Google Analytics at all as you can insert tags from any service provider (Social pixels, Intercom-like services...)
If you use Google Tag Manager to handle those tags you should remove the script call from your code. Otherwise it will be invoked twice

Edit a google spreadsheet using javascript/client side code

I am new to google spreadsheets.
I am trying to use them for a small website where instead of maintaining a DB, I am storing and fetching data from sheets using APIs.
I found this library - https://github.com/mikeymckay/google-spreadsheet-javascript , for fetching data from a published sheet.
It serves my purpose of doing everything in the browser.
But I am not able to figure out how can I write data to same/different spreadsheet.
Do I use Sheet APIs? Can I also do it using App Script ? Is there a ready to use library for the same ?
Can someone please help?
You'd likely want to check out the Google Drive API, rather than Google Apps Scripts. I don't have much experience with it, especially in regards to using it on a website, but that's the best direction to head in.

How can I get a client location using the Google Map (Geocoding) Javascript API using pure javascript?

There are plenty of examples all over the internet, including stakoverflow, of getting location information. But every single one that I find uses HTML to include the library (<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true"></script>) and display the information. I need to get the client location from a script, not a web page. I just need to get the location information - I don't need to display it. No HTNML - just javascript.
I've tried several of the examples found on this site, but they all use the navigator.geolocation or google.maps classes, neither of which are recognized by Google Scripting. I've tried to include a resource, but maps nor navigator or any of the required APIs are in the list. I've even attempted to find a RESTful way to use the API and get a JSON response; found nothing even close.
The example used in several places is this one on developers.google.com, including several appearances in stackoverflow like this one.
I suppose it could be a very "newbie" issue, but I'm flummoxed!

blogengine without php or asp.net etc

Is there a way to have a blog directly integrated into my HTML/javascript-only website, without having to have something like a SQL-database and a dynamic engine like PHP or MySQL?
Maybe there is some service in the web that offers this (hopefully without ads :) ). Or maybe I can have a blog engine entirely written in javasript?
Entirely written in JavaScript? Surely that defeats the entire point of having a "blog-engine" in the first place? The point being that the data is stored somewhere and dynamically retrieved. To avoid using anything server-side (which seems to be your intent), and only use HTML/JavaScript, you'd have to store all the data for the blog in files that are served up to each visitor, and then retrieve the data from the particular, local, locations using JavaScript.
Sorry if I'm misunderstanding the point here... but this seems to be an utterly useless way of trying to go about things. Blogs are, in general, either written statically (in HTML [even though this is rare]), or are dynamically generated from a database by a server-side scripting language (most common).
Edit: As an additional point, I suppose you could include some third-party blog feed, or service, in your page, via use of JavaScript... but I'm unsure as to which (if any) blogging services would directly support this method of working. Additionally, this is quite an unreliable way of including third-party data in a page...
Here's a thought. It's not really a blog engine - but a wiki.
Entirely javascript/html/css. All lives in a single html file:
http://www.tiddlywiki.com/
not sure how it would work on a real live site, but their site is using it:
* A personal notebook
* A GTD ("Getting Things Done") productivity tool
* A collaboration tool
* For building websites (this site is a TiddlyWiki file!)
* For rapid prototyping
* ...and much more!
You could use github pages. You will get a generated blog with version control.
Other option is to use a Desktop blog tool and then update your site.
You can user iWeb if you have a Mac or CityDesk on Windows or you may try this open source tool
Edit Today I came across this tool: Zeta producer that may help.
http://code.google.com/p/showdown-blog/
Blog engine written in just JS and XML [v0.6] {JavaScript, XML}
So, what you want is to have a blog where you're website provider doesn't provide a way to serve dynamic content?
The only way I see that you can do it in that case is writing html-files (or text-files if you prefer) and adding them to the site. After that you can have some JavaScript to add them to your "blog-page".
You of course need to upload them to the website in the same way as you do for the other files, and then have a way for the JavaScript to know which pages it should fetch.
I am not aware of any JavaScript blog-engines, but you can have a look at the templating functions in for instance Prototype
Of course, that means that you will have to fetch both the template and the content through Ajax and let the client do all the processing (could be slow and possibly insecure), and you still need to have a place to upload the content and update it.
Your best bet is going to be using a generator to create the HTML/CSS/JS to upload to your server, take a look at Webby: http://webby.rubyforge.org/
IF you really need to you can use a public api for a service that lets you post small bits of info and retrieve it using javascript.
for example if you only need small posts you can make a blog in html.javascript that utilizes twitter as the engine. of course you will be limited to 140 chars. I am sure there are other services that will allow a similar idea but with less restrictions.
And of course the best option - Get a blog software or host your blog with a service provider and link to it from you site.
Good luck
One solution would be to use some application that generates the static web pages of your blog, and uploads them to your web server. This way you'd have a blog with static content that could all be managed in javascript alongside your existing site, without needing to install database, daemon software, or additional dynamic web programming languages on your server. The static content generation could happen directly on your server if possible, or you could run the html generation tool locally and upload the output.
MoveableType has a tool like this. You still need somewhere to store the content of your blog, and for this MoveableType uses MySQL by default, so you'd still need to install a database somewhere, but the database could simply be one your local desktop.
MoveableType also has support via plugins or older versions that can retrieve data from a sqlite or other database. The advantage of sqlite is that it doesn't require installing daemons like MySQL does, you can just put a sqlite file on disk somewhere, give MoveableType the path to the file, and run the script to generate your static content.
There are likely other tools like MoveableType, and I have in the past generated blog-like web pages simply by writing small scripts to generate HTML. The main issue is just that you need somewhere for these scripts to fetch data from.
Another option might be to develop your blog using XSLT, ... with XSLT, you'd put the content of your pages in XML files, and then write a template in XSL that converts your XML to HTML.
If you google for 'static blog site generation' you might find other ideas/options, including Jekyll/github mentioned in one of the other responses.

Categories