We are finding a new behavior in the export API between new google sheets and old google sheets.
It is also somewhat unclear exactly where the endpoints are supposed to be- my understanding is that everything should move to the drive API eventually.
So, what we are doing is first getting the information for the document using:
https://www.googleapis.com/drive/v2/files/
This works fine, and we get all the info.
Within that, we have the export links that look like this:
"exportLinks": {
"text/csv": "https://docs.google.com/spreadsheets/export?id=&exportFormat=csv",
"application/pdf": "https://docs.google.com/spreadsheets/export?id=&exportFormat=pdf",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "https://docs.google.com/spreadsheets/export?id=&exportFormat=xlsx"
}
Directing us to use the docs.google.com endpoint, which we do.
When we use the "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" link (excel format) this works fine for OLD Google Sheets.
However, for new google sheets we get a redirect to an endpoint that is in our Google Apps domain of the format like this:
https://www.google.com/a/.com/ServiceLogin? etc.
We have put the OAuth token in the header, again, this works fine with old sheets but not with new sheets. If we remove the token, then it redirects us to yet another signin page.
Why is it redirecting rather than returning a 403 unauthorized if there is an issue with the authentication? Why only for NEW sheets not old?
This results in some HTML being returned, not the file- as if we were a browser.
So the question is two fold-
1) how do we download new sheets in excel format programmatically using Oauth
and 2) If its different than old sheets how do we detect which is which so we can support both?
Related
Using API to get access_token and now I need to open Google Sheet.
Step 1.
Authorization: Bearer ya29.a0AV...." together with link: "https://docs.google.com/spreadsheets/u/0/d/[DocumentFileID]/edit"
Step 2.
Now HTML document back (~200kb). I'm using libcurl for that.
The problem is - missing are some css and js files and I see document just partially. Is there any way to open/edit Google Sheet using API?
I know for the option to just open https://docs.google.com/spreadsheets/u/0/d/[DocumentFileID]/edit in the new browser tab, but in that case I need to manually login to Google and that's what I try to avoid, because I want to use API to login and to open/edit a Sheet.
I also know for the option to share a document but I also try to avoid that. I'm writing application to customers who can access they own documents once they confirmed API usage.
I think you may have misunderstood what the google sheets api can do
The Google Sheets API is a RESTful interface that lets you read and modify a spreadsheet's data.
It gives you access to the data, it does not allow you to open the google sheets web application. Your going to have to code your own google sheets type app if you want users to open sheets directly.
I am writing a google apps script to process bulk add/remove editors for some new Google Sites.
I am aware that google apps script currently doesn't support new google sites so I am trying to use DriveApp to manage the editors.
However the script doesn't work and returns the following:
Exception: Service error: Drive
whenever file.addEditor() or file.removeEditor() is used. I guess this just doesn't work for new Google Sites.
Are there other workarounds?
Make sure you're using the correct FileId with Sites as it's not quite as simple to acquire compared to other file types on Google Drive. When you're editing a Site page, the FileId can be found in the URL between /d/ and /p/.
Example: https://sites.google.com/d/????? this the file id ?????/p/!!!! not here !!!!/edit
I just successfully ran the below code to add/remove editors of a new Google Site.
const zFile= DriveApp.getFileById("????? this the file id ?????");
function addEditor(){
zFile.addEditor("pgsystemtester#gmail.com");
}
function removeEditor(){
zFile.removeEditor("pgsystemtester#gmail.com");
}
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 have a Python cron job that pulls urls from sheet1 and populates sheet2 with scraped data from each url. Sheet 2 consists of [url, title, body, image urls]
I have an Old Google Site where I manually take sheet2's contents and create a new post. I want to automate this.
Structurally speaking would Google Scripts be able to pull and publish this dynamically? Lets say every time Sheet2 is updated (or a set interval).
I've worked with gscripts but never touched Google Sites before today.
The answer is probably yes. Apps script can do this. You have a couple of options.
Old Google sites
Option 1
Embed an apps script into the site as an iframe and stream you posts in that.
Option 2
Use either a standalone apps script or one attached to the google site and update the site using the Google Sites API.
New Google sites
Currently there is no apps script API for the new google sites. But you can embed JS HTML etc as a frame in the new sites. You can even use CDN libraries. Which means you can pull data from your sheet using something like AJAX.
Custom built option
The Google Sites API can be accessed anywhere you can handle Oauth. This means you can update Google Site from server-side code or from any client if you can handle Oauth.
I know how to important HTML Data into Google Sheets so that it displays, but I am trying to figure out if it is possible to also copy a web data entry form into Google Sheets, so that you can enter values, which would then be presented by the data.
I am trying to import this calculator into Google Sheets so that I can work with the real time values.
http://www.coinwarz.com/calculators/ethereum-mining-calculator
Any ideas about how I can do this?
I am not aware of any way to import the actual HTML form into Google Sheets. However, here is how I would do it:
I would open Chrome and find the outgoing POST request that occurs when you press the green Calculate button on that site.
I would use Postman to test and create the request and see if it works.
Using Google Apps Script, you can issue HTTP requests. I would re-construct the request being sent in Google Apps Script.
To make it look nicer, you can re-construct the calculator in your Google Sheet. You can recreate the calculator's input buttons as cells and then fetch those cells in your GAS code (like, hash_rate_cell.getValue()):