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
Related
Is it possible to call any of the Google Sheets formulas from within your own Google Apps script custom function? If so, how?
It obviously doesn't work to merely use the formula name like you would inside the sheet. Like this, which is what I was hoping would work:
function myCustomFunction() {
return TDIST(1,30,1); // calling =myCustomFunction() does not work due to TDIST giving a ReferenceError, even though =TDIST(1,30,1) works inside the spreadsheet
}
But since Google's built-in formulas probably rely on some JS implemented functions, it would be strange if there wasn't an API so that we could reuse those functions easily. I've looked at the Google Sheets API reference, but it seems made for calling your custom functions from external services. It seems you may call Google's own formulas through such a POST request. But that seems terribly cumbersome, when you ought to be able to refer to them directly from within your custom script which is tied to the specific Google Sheet environment anyway. If not, then what is the least roundabout way of using those inbuilt formula functions from within a custom function?
This has been a feature request since 2011 and has been declined by Google citing inter team issues.
Status: Won't Fix (Infeasible) by ev....#google.com
We have requested this of the Spreadsheet team, and are marking as "Won't Fix" for now.
Apparently, The spreadsheet team hasn't responded yet. A related product forum post states that Google has no intention of integrating spreadsheet functions with scripts.
I have a Google Script library that is used by at least 100 other scripts (some that are bound to spreadsheets/documents, some that are not). How can I find all of these client scripts that reference my library script?
More specifically, I need to be able to add a new feature into the library that requires new permissions that I (the user) must grant. The client scripts won't run if I just add this feature to the library without granting the permissions to each of the client scripts. So ultimately, I need to give this new permission to each of the clients. And if I knew what scripts were actually using this library, I could do that manually for each one. But I need to URL's or ID's or something for each of those scripts.
Answer:
Unfortunately this is not possible to do.
More Information
It is possible to get a list of standalone Scripts from your Drive, though scripts bound to a file can not be searched for using regular searching methods.
It is possible, using the help of this Google Account page to get a list of all the Apps that have access to your account, though only files you have authorised will appear here, and apps which are not just those created by you in Apps Script will appear there (for example, other add-ons or even Android Apps bound to your account appear here).
A Partial Workaround:
Using Google Apps Script, you can list all Apps Script Projects that you own with help of the MimeType enumeration GOOGLE_APPS_SCRIPT
var scripts = DriveApp.getFilesByType(MimeType.GOOGLE_APPS_SCRIPT);
var arr =[ ];
while (scripts.hasNext()) {
var script = scripts.next();
arr.push(script)
}
Logger.log(arr);
Or even just searching for type:script in Drive, however this only returns a list of scripts that are not bound to a file.
You can then use regular Google Drive search terms to find which of these files contain, for example, a unique method name that the library uses. I am aware this isn't a perfect solution and you would still have to look for projects bound to a file using the above webpage.
Feature Request:
It appears that back in 2014 a feature request for this was made on Google's Issue Tracker, though I would suggest creating another feature request for this here as it was marked as a duplicate of another issue. You can make a feature request under the correct Apps Script component here.
References:
Google Apps Script - Enum MimeType
Google Drive Search Query Terms
Apps with access to your account
Google's Issue Tracker
Feature Request: Listing and searching for container bound scripts
Create an Apps Script Feature Request
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.
What is the difference? Can you combine Google Apps Script with Google Rest API? Or is the Execution API the alternative?
Thanks, I really appreciate it.
The Execution API is a REST API.
There is no such thing as the Google REST API since REST is an architecture, not a Google service. Many Google APIs have REST or at least REST-like interfaces.
REST is an acronym for representational state transfer. As per usual it is impossible to explain this without provoking dozens of comments that point out the explanation is wrong or incomplete, so I refer you to the Wikipedia page.. But important features of REST are that resources are represented by URLs and that different http verbs (get, put, post etc) can evoke different responses from the server for similar resources (which adds purposefully a few constraints, i.e. GET is not supposed to do destructive operations etc.).
So "REST" is a specific way to design an API and Google used this design for the Apps Script Execution API.
These are entirely separate.
The Google REST API's are provided by Google and allow you to interact with their services from an external location. Essentially your code can call code written by Google, to impact Google services.
The Google Apps Script Execution API allows you to expose functions you have written in Google Apps Script to be called from an external location. Essentially this allows you to call custom code which is hosted by Google from an external location.
The key difference here is that the Google REST API has nothing to do with Google Apps Script, while the Execution API is all about letting you call Google Apps Script code.
You can certainly mix both in a given project, depending on what you are trying to do. Google Apps Script can even make use of the REST API, although
that is often not needed.
If you are trying to figure out which one you need, read about Google Apps Script and determine if working in that language is suitable for your project.
If you are planning to work from another language like Python or Java, then you probably need the REST API. Finally, if you want to work in Python or Java, but call some pieces of code written in Apps Script, then you should look at the Apps Script Execution API.
I'm using google spreadsheet with Google Apps Script.
but it gives me error message too easily. like this
Error
Script invoked too many times per second for this Google user account. (line 0).
Is there any way to avoid the error? (except the way reduce function call)
or alternative Spreadsheet program that support Javascript function define?
As noted in the documentation you can work around this by ensuring that your function supports ranges, and the function on a range. See also the section on Optimization on the Custom Functions in Google Sheets page.
To create a custom function you should use Google Apps Script, it's the only way. Regarding the way to avoid the error, there are several things that could be done but to be certain about what is required in your case you should add more details.