Using BigQuery API with Google App Maker - google-apps-script

Has anybody had any experience with using BigQuery with Google App Maker? Specifically, creating a data source for a Google Drive Table through Apps Script.
I use a script in google sheets to use BigQuery API, run a job and return the output to a sheet, but i'm unsure how to modify this to work in App Maker - any advice?
best wishes
Dave

Sorry for the vague answer, maybe someone else can provide a better one with a concrete example.
If you've already got an Apps Script script, then this should be easy. What you probably want to do is implement a Calculated Model in order to get the results from BigQuery to your application. In short, a Calculated model will let you define a custom schema, and then write Apps Script code to query BigQuery and then create, fill, and return records (which will be very similar to the code you wrote to fill sheets). Once you've done this you can use the calculated model like you would a normal SQL or Drive Tables model.
You can read more here: https://developers.google.com/appmaker/models/calculated
and using this sample (although the use case for calculated models in this sample is quite different than what you're doing): https://developers.google.com/appmaker/samples/calculated-model/
Just like Apps Script you'll also need to enable the Big Query Advanced Service, you can find that in the application settings screen, all the way at the bottom, ("Advanced Services")

Related

Inserting images to a multiple choice field in Google Forms using Apps Script

I would like to create a poll in Google Forms where the users could vote on their favorite image. For this, I'd like to create a multiple choice question, where every choice is an image. Since the amount of images is large, I'm looking for a way to automate this process - creating a multiple choice question out of the images in a Google Drive folder.
I've examined the Google Forms API, as well as searched for similar questions, but I couldn't find any API that would let me do this programmatically using Apps Script.
I was wondering if anyone knows if this action is possible, and if so, how?
Example image
Here's an example of what I'm trying to achieve - the script constructs a form from images of trees that exist in a folder in my Google Drive.
Thank you for your time!

Adword Script in Google App Scripts

I am not able to find Adword API support in Google App Script,I can write adword script from adword account but currently i'm handling multiple account(almost 25) what i have to do is go inside individual account and copy my script in that account and adword script have limitation of maximum 15 script can be run by one user at a time, i want to create database of all account at one place that is possible through adword api in java and other programming languages,but i'm quite familiar with Google App script i want to use Adword API in App Script,how can i use UrlFetch() class of Google App Script to use adword api, so that just by replacing client Id of adword account i can get all data at one place(i have access to all account so no need to change username and password).
Thanks in advance for any help and information!
If I understand correctly, the main problem is that you want to to basicaly make a "code library?" So reuse the same bits of code between accounts?
One option is to use the Eval function, as detailed in tip 3 of this article: http://www.ppchero.com/tricks-for-running-adwords-scripts-in-multiple-accounts/. A second example of using this same method is here: http://www.freeadwordsscripts.com/2013/10/use-gdrive-to-load-single-adwords.html
You would then upload this into Google Drive, or point this to the location of the Google Script.
Another option, as detailed in the PPC Hero Article, is to use Google Sheets to pass the variables you need from one script to another. Basically, the SpreadsheetApp function works within all AdWords scripts, so you can use this to pass data along from external sources.
There are some example scripts regarding Adwords associated with these posts:
http://searchengineland.com/four-ways-you-can-benefit-by-using-adwords-scripts-145530
http://googleappsdeveloper.blogspot.co.uk/2012/12/adwords-analysis-in-google-apps-script.html?m=1

Connect Google Drive to Could SQL

I am looking to try and combine Google's Cloud SQL service with google drive. Essentially I want to use Google forms for the user to easily input data, and then have that data feed into the Cloud SQL environment (from which I can do reporting and analysis).
My question is, has anyone done this already, or have any ideas of how this might be accomplished? I already have google forms writing to spreadsheets, and that works fine. I am familiar with SQL so creating reports and pulling data from the Cloud SQL environment shouldn't be hard.....but I don't know how to connect the two.
Ideally I would like something to run on a schedule (maybe on a nightly basis) to pull the data from a google spreadsheet, update the Cloud SQL database, and clear the old data from the spreadsheet.
I think the best way to do this would be to use Google Apps Script.
Apps Script allows you, for a given form, to define an onSubmit() method that will be called when someone submitted an answer to the form.
Then you can use the JDBC service to connect to Cloud SQL.

How can I add a Google apps script to a spreadsheet created using the API?

After reading up a lot on the Google Spreadsheet API I have come to the conclusion that formatting (such as merging cells, changing fonts etc) is only available throught the Apps scripts.
Since we need to create and fill the spreadsheets with data programatically using Java on the back-end I guess I need to somehow either;
link the new sheet to a Apps script that trigger on-load or
create a Apps script that creates the spreadsheet for me.
Anyone knows?
If you want to just "create" the spreadsheet, you don't need a script to load whenever it spreadsheet is opened. It's probably easier to develop a script that runs once and create the spreadsheet for you.
Another tip is to have a template file that you can copy with most of the formatting (if not all) already there. Possibly pending just little things that are related to the real data the new spreadsheet will have.
Edit to answer the question in the title.
No, you can not add a script to an existing spreadsheet programatically, only manually. What you can do is previously set up a template spreadsheet with a script in it and create new spreadsheets by copying this template.
(answering the comment)
You can run a script programatically, but not upload it. To run a script you can deploy it as a web-app and call its url with either a http get or post (will call its doGet or doPost functions, that you must have declared). Also, you could set this script to run on form submit of any spreadsheet-form and just submit a set of answers to this form. At last (that I can think of now) you could just add the script as a library in another Apps Script and call it directly.
(Aug 2016) There is no way programmatic way to link a Google Sheet and Apps Script code other than manually. Based on what it seems you want ("create and fill the spreadsheets with data programatically using Java"), you can now do it without Apps Script.
TL;DR: Above, #Henrique has answered multiple questions and even questions that weren't asked! The good news is that today, we have more answers representing alternate possible solutions to what you're seeking.
It's now possible to "upload" Apps Script code programmatically with the
import/export system, say with Eclipse since you're a Java developer (2013 announcement).
I agree with Henrique's suggestion that if you create a spreadsheet
template, i.e., Excel file, you can use the Google Drive API to
programmatically import/create identical Google Sheets with all your
desired formatting.
"Formatting (such as merging cells, changing
fonts etc)" can now be done outside of Apps Script, as there is a
"new" Google Sheets API v4 (not GData).
In order to use the new API, you need to get the Google APIs Client Library for Java and use the latest Sheets API, which is much more powerful and flexible than any previous API. Here's one code sample to help get you started. If you're not "allergic" to Python, I also made a video with a different, slightly longer example introducing the new API and gave a deeper dive into its code via a blogpost that you can learn from.
Note the v4 API allows you to create spreadsheets & sheets, upload & download data, as well as, in the general sense, programmatically access a Sheet as if you were using the user interface (create frozen rows, perform cell formatting, resizing rows/columns, adding pivot tables, creating charts, etc.), but to perform file-level access such as uploads & downloads, imports & exports (same as uploads & downloads but conversion to/from Google Apps formats), you would use the Drive API instead.

convert csv to Google spreadsheet in a html form

I have a small html form with some options. Based on the user's selection, currently the button click will result in the downloading of a csv file with the relevant information. What I ideally like to do is to be able to generate programatically a Google Spreadsheet from that csv file when the user requests it via the form.
I couldn't find this info. Will I need Spreadsheet's APIs for this or is there a simpler way?
Many thanks!
Yes, you need to use the Google Documents List Data API. Which will require that you make and authenticated POST call to this API with the appropriate parameters (described on the link). For Java and .NET Google developed some libraries that makes this job much easier, but you can call the API from any app/lang, just take a look at the "protocol" explanations on the documentation.
A think a simpler way would be to use Google Apps Script, a server-side javascript built into Google Spreadsheets and Sites. It's possible to write an interface to look like your html form. You'll have the advantage of it being highly integrated with Google spreadsheets. With 2 lines of code (literally) you can create a new spreadsheet with you csv values.