This question already has an answer here:
publish a Google Spreadsheet through Google Apps Scripts
(1 answer)
Closed 3 months ago.
Is there any plan to provide Google Apps Script capability for the "Files | Publish to the web..." menu item in a Google Document?
This has been asked before, but heck if I can find an answer. To be clear, I don't mean setting the sharing or viewability of the Document itself, I mean the thing where a web page representation of the Document with its own link is generated.
There is now a method for this, provided here.
First, add the service Drive API
var docId = "###"; // Please set this.
Drive.Revisions.update({published: true, publishedOutsideDomain: true, publishAuto: true}, docId, 1);
It is not possible directly with GAS. However, using the Document List API and URLFetch with oAuth, you can, in theory make a document public on the web. Publish to the web option, per se, isn't available though.
Please see the following links for information and help
How do I get an access token using UrlFetchApp with GAS
https://developers.google.com/google-apps/documents-list/#sharing_resources_with_the_public_the_rest_of_the_internet
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 trying to develop a Google Document add-on to manage linked Google Spreadsheet tables in a Google Doc.
For example to allow updating of the source Google Sheet cells with changes applied to the linked cells of the Google Doc.
Although I can find the class list, there doesn't seem to the equivalent of an inlineLinkedTable class.
This post asks the same question but it wasn't answered.
What class should I be looking at or service.
Thanks,
Rob
It's not possible update Docs linked Tables from the API or Apps Script service.
There is a feature request asking for this feature to be implemented. You can click on the star next to the issue number to receive updates and to give more priority to the request.
Even thought you are using Apps Script in your example, this is also applicable to the DocumentApp service.
This question already has answers here:
Share a Drive document without notifying user with Google Apps Script
(3 answers)
Closed 5 years ago.
I have a google-appmaker project where I add the list of possible viewers down the workflow chain to a file. Once the user attaches a file and starts the workflow, I take the attached file and the viewers down the chain to it so that they can view it.
However when I use it, it also sends another email to the user, and the viewers that the file is shared. Ideally I'd like to add them without triggering the email since there is also another email that goes when the workflow starts. Is there a way to add viewers without notifying them file.addViewers doc.
Thanks
This can be done using the advanced Drive API.
Documentation is here
and code goes like this :
function testFileSharing() {
shareFile("14fQ#################9SW2SIIutz5qk");
}
function shareFile(ID){
var permission = Drive.Permissions.insert({value:"test#gmail.com",role:"reader",type:"user"},ID,{sendNotificationEmails:false,emailMessage:"testing for you"});
Logger.log(JSON.stringify(permission));
}
The advanced Drive API must be enabled in the ressources menu and in the Google API Console.
This question already has answers here:
Do Google Apps scripts permit any sort of introspection?
(2 answers)
Closed 5 months ago.
Can a Google Apps Script determine its own resource id? If it could, then it could discover what folders it is in (parents).
If it is only in one folder, then it could use that folder as a default folder for various purposes.
If it is in multiple folders, then the resource id is insufficient to truly identify where the script was started from, so the corollary question is can a Google apps script determine the resource id of the folder it was launched from?
Seems like these would be useful additions, maybe to Class Session, if it doesn't already exist somewhere that I have missed.
For a Spreadsheet I found this to work:
var thisFileId = SpreadsheetApp.getActive().getId();
var thisFile = DocsList.getFileById(thisfileId);
As per my knowledge, there is no option in Google Apps Script to get its own resource ID. You should file a feature request in Google Apps Script Issue tracker.
There doesn't seem to be (to my knowledge) an API to edit Google Docs (not spreadsheets, their HTML based documents). Has anyone done something like the? Maybe by downloading the HTML version, editing and uploading the changes?
UPDATE (May 2019) The Google Docs API was officially launched in Feb 2019. The documentation is located at the link from my update in July below. A few weeks after launch, I produced a high-level video overview of what a mail merge application using the API would look like. (It's not a full-fledged G Suite Dev Show episode but does link to a working sample.)
UPDATE (Jul 2018) The Google Docs team pre-announced a forthcoming REST API at Google Cloud NEXT '18. Developers interested in getting into the early access program for the new API should register at https://developers.google.com/docs. The original answer below still stands as the REST API will become the second way you can access Google Docs programmatically.
Original answer (Mar 2017): (Most other answers are outdated.) Google Docs does not currently have a REST API, however developers can programmatically access (CRUD) documents using Google Apps Script, server-side JavaScript apps that are hosted at and run in Google's cloud. If you're new to Apps Script or to editing Google Docs with it, here are some learning resources:
Your first script which creates & edits a Doc, then uses Gmail to send it
to you.
I've got 4 intro videos for you (mostly Sheets-flavored)
They're in this playlist (see videos 5, 8, 22, 24)
Any forthcoming videos will be in this series
Useful pages in the official docs
How to CRUD Google Docs with Apps Script overview page
Extend Docs functionality by creating Docs add-ons via this quickstart
Apps Script reference documentation for Google Docs (Document Service)
See Google Docs add-ons that other developers have built
Simple example: if you have an existing Doc with a (Drive) file ID of DOCUMENT_ID_GOES_HERE, here's how you'd basically edit it with Apps Script, doing a pseudo "mail merge" of name & email into the document given placeholders {NAME} and {ADDR}:
function mergeNameEmail() {
// Open a document by ID
var doc = DocumentApp.openById(DOCUMENT_ID_GOES_HERE);
// Access the body of the document
var body = doc.getBody();
// Merge name & address from template
body.replaceText("{NAME}", "Ima Developer");
body.replaceText("{ADDR}", "123 Main St, Anytown, XX 00000");
}
The Document List API has been deprecated since September 2012 and looks like it could be retired after April 2015.
Updating the HTML version using the Drive API, as the question suggests, looks to be the only other way. I have been trying this and I have experienced a few of issues.
Comments are converted into citations and added to end of document.
If someone else is editing the doc via the browser any changes made by them between the API read and update time are lost.
Updates to a doc can break the formatting. For example I updated a doc several times and the vertical spacing between some elements (h1's, h2's etc) kept widening each time and ruined the doc.
When an API update occurs the cursor of anyone in the doc is moved to the top of the page.
There may be more issues. These are just the ones I have found in the last few days.
Not really sure if this is what you're looking for exactly but have you taken a look here http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html It looks like it allows editing for content (v3.0 anyway).
There is com.google.api.services.drive.model.File.getExportLinks
You can get a Google Doc as a docx (for example), edit it using your favourite docx editor, then upload again. See the samples for doing this (starting with GoogleDriveDownloadAsDocx) in the context of docx4j. Note the README.
Or do the same with any of the other export formats.
(2019) Google now provides API for docs, slides, sheets, drive.
There is a sample app for this, Dr. Edit, on Google Drive's documentation.