How to improve speed of the custom gviz query function? - google-apps-script

In this post there is a custom function built that returns data based on gviz query.
How to use Google sheets query or Google visualization api from apps script?
But it is little slower, is there any way to make it fast or any other technique?
like using out:csv ?

Related

Can you write Google finance directly to an array?

Can googlefinance write results directly to an array? I am currently writing it to a sheet first and then pulling the sheet range into the array. It would save a lot of processing if I could write it directly to an array so I am investigating. If you have knowledge and expertise on this could you let me know?
I get an error when I try. Is it just incorrect syntax or is what I am trying to do not possible? I would like to avoid writing to the sheet to save on time and in sheet processing. But not sure if the function is allowed to write into a variable instead of a sheet
function TEST() {
var APPLEPRICEARRAY = GOOGLEFINANCE("AAPL","price","1/1/2009","12/31/2020","WEEKLY")
};
Is it just incorrect syntax?
You seem to confuse functions (formulas) that are exposed in the Google Sheets application with services that are available in Google Apps Script environment. What you wrote would require GOOGLEFINANCE to be a service "attached" to global scope, so yes, this is incorrect.
But the error you get is not a syntax error, your reference is invalid (no GOOGLEFINANCE variable is ever declared in the global scope, therefore none can be referenced), hence you get ReferenceError.
Can googlefinance write results directly to an array?
No, for reasons explained above, it cannot. I apologize for this, but you are comparing apples with oranges: an array is a data structure (an indexed collection, to be precise) in JavaScript (on which Google Apps Script language is based), while formulas are not even built-in objects: they are not part of the language.
Is what I am trying to do not possible?
Unfortunately, Google Finance API has been shut down for a long time now, so no, not possible.
Not screaming with ALL-CAPS is considered a common courtesy as well
In the code example is shown that you are trying to use a Google Sheets function as a Google Apps Script / JavaScript function. That is not possible.
Unfortunately there isn't Google Apps Script advanced service for Google Finance and there isn't a API.
From https://groups.google.com/g/google-finance-apis
Dear Finance API users,
As you may have heard from the Google Developers Blog, Google is doing an API spring cleaning. One of the APIs affected is the Google Finance API (both the Portfolio API and the Finance Gadgets and Tools API), which will be shut down on October 20, 2012.
References
https://developers.google.com/apps-script/guides/services/advanced

How to orderBy Conversion Cost or CPA when writing to Google Sheets

I'm using Google app scripts to write data to Google Sheets with custom calculations which is why I'm using scripts instead of a straight export of the data. When the data is written into Google Sheets, I want it sorted by Cost/Conv or CPA.
The current script sorts by Conversions:
var kw=AdWordsApp.keywords().withCondition("Conversions >1").withCondition("Status =ENABLED").forDateRange("20180101", "20180801").orderBy("Conversions DESC").withLimit(100).get();
How do I sort by conversion cost or cpa?
I looked through Googles documentation and even called their support team. Couldn't find the answer. I feel like this should be simple but I can't figure it out.

Using BigQuery API with Google App Maker

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")

How to use ImportXML in a Google Script?

Scenario:
I am trying to use Google spreadsheet to do something like this:
I've a set of Blog URL's (more than 50) for which I want to fetch title
Currently I am using the formula: ImportXML(A2,"//h1[#class='entry-title']" )
The Problem w/ this approach is that ImportXML calls are limited to 50 per spreadsheet and I've more than 50.
I browsed/searched - found out that we can use ImportXML calls in google apps script but did not found any example.
I found this: https://developers.google.com/apps-script/articles/XML_tutorial but I was hoping to use ImportXML function.
Can anyone describe or point to a resource where they have used ImportXML in a google apps script? Thanks!
I would use a few spreadsheets, then pull the results together into a master spreadsheet, or are you doing >1000 or so. If you have lots, the XML_tutorial link you have is the place to start.
But last time I checked, google-apps-script does not support google spreadsheet functions, if I remember, the feature request to support all spreadsheet functions in GAS was rejected.

Using Google Drive PHP API to read and write Google Doc tables

I'm thinking about the followin scenario:
My PHP application push some integers into a google doc table which calculates with this and saves the result of this operations at the end of the table. my php application finally reads the result and displays it on the website.
Is this possible with the Google Drive PHP API?
I found the following:
http://code.google.com/p/google-api-php-client/
https://developers.google.com/drive/
https://developers.google.com/drive/examples/php#setting_up_this_sample_application
But I'm not sure if this would be possible at all? Are there any example applications or scripts in order to read and write google doc tables?
You can use the Spreadsheets API to programmatically read and write to a Google Spreadsheet:
https://developers.google.com/google-apps/spreadsheets/