I have a spreadsheet, ex.:
https://docs.google.com/spreadsheets/d/1_qVnTw1Cwb2Ziwta_N0p-V4_ptD6-ZypDvCIrnryNFU/pubhtml
that I want to download as a CSV file. To do this, I believe I must download it from a link similar to this:
https://spreadsheets.google.com/pub?hl=en&hl=en&key={INSERT KEY HERE}&output=csv
But my question is, how do I go about getting the "key"?
Append the /export?format=csv just after the document id in the URL.
So in your case, the URL should look like this:
https://docs.google.com/spreadsheets/d/1_qVnTw1Cwb2Ziwta_N0p-V4_ptD6-ZypDvCIrnryNF/export?format=csv
Of course, this must link to an existing sheet that is publicly shared (for viewing)
Related
I need to fetch a simple document template file (.doc) from google docs (or drive), then fill in the missing details and save the document as new file into the cloud.
Could someone advise on how to achieve this using the Google Docs API so this could be done within bespoke environment?
thanks in advance
If I understand you correctly, you want to programmatically:
Retrieve a document from Drive.
Edit this document while keeping the original one unmodified.
Save this new document.
You have to follow these steps:
Use Files.copy from Drive API to copy the file you want to edit. To achieve this, you have to provide the id of the original file as a request parameter. As a response you will get a File resource corresponding to the copy you created. Retrieve the file id from this response.
Update this new file using batchUpdate from Docs API. For that you will need to (1) provide the file id you retrieved in the previous step as a parameter and (2) provide the changes you want to make using the requests parameter (an array of all the changes you want to make) in the request body (check the links I attach to know exactly how should your requests parameter be like - I would like to be more specific here, but I don't know how exactly do you want to modify the document).
Obviously, there is no need to save the modified document, this is done automatically when the file is modified.
I hope this is of any help to you.
I have a Google Docs document which contains one image. I found images's objectId as stated here https://developers.google.com/docs/api/reference/rest/v1/InlineObject but I can't understand how to get an url to that image.
I tried searching for this objectId in Drive but it returns File not found.
Any ideas ?
Update
As noted by #Tanaike the image info is contained in the result.inlineObjects and
not directly in the paragraph.
You want to retrieve the URL of the inserted image in Google Document using Google Docs API.
If my understanding is correct, how about this answer?
I think that the property of inlineObjectElement that you are checking is in the paragraph. The information of the inserted images can be seen at the property of inlineObjects. And the URL can be seen at the property of ImageProperties.
The endpoint is as follows.
Endpoint:
GET https://docs.googleapis.com/v1/documents/{documentId}?fields=inlineObjects
Here, as a sample, inlineObjects is used as fields. You can also use * as fields.
Result:
The URL can be retrieved as follows. It supposes that response is the returned value from above endpoint.
url = response.inlineObjects["kix.###"].inlineObjectProperties.embeddedObject.imageProperties.sourceUri
kix.### is inlineObjectId in your question.
If the image is inserted from the URL of outside, the URL is the same with the URL which was used when the image was inserted.
If the image is inserted from Google Drive, the URL is like below.
https://lh3.google.com/u/0/d/{fileId}=w###-h###
In this case, {fileId} is the file ID of the image. You can retrieve the original file using this file ID.
References:
Method: documents.get
InlineObject
ImageProperties
If I misunderstood your question and this was not the result you want, I apologize.
Step #1: Right-click and Copy the image from the Google Doc.
Step #2: Paste into dynalist.io.
(Note: Dynalist doesn't allow you to paste images, but you can paste images from Google Docs because it just adds the link.)
I understand that this may not help if you are trying to do something with the API, but for finding the link to a single image, it is the simplest method I've found.
use the drive and doc api
use the gdoc api retrieve the ContentUri:
(Document.InlineObjects[imageid].InlineObjectProperties.EmbeddedObject.ImageProperties.ContentUri)
imageid has the form "kix.###..."
The imageid can be retrieved frm the InlineObjects map, the key is the imageid
After obtaining the ContentUri you must strip the ending "=wxx-hyy" to obtain the the image file id for the drive api
use the drive api to obtain the file pointer:
*fil, err = service.Files.Get(fileid).Do()
After obtaining the file pointer, you can retrieve the image file characteristics (see File)
Alternatively the image file can be downloaded via:
httpResp, err =service.Files.Export(fileid, mime).Download()
mime types are listed here
I am creating an webpage that allows my users to select from a list of presentations (.ppt and .pptx) I have stored in a Google Drive folder. I can query the folder and list the files easily enough and using the alternateLink property I can get a link that opens the file for editing in the Google Slides app, like so:
https://docs.google.com/file/d/<ID property of File goes here>/edit?usp=drivesdk
I want to get the link that is created when you view the presentation, like this:
https://docs.google.com/presentation/d/<some ID goes here>/edit#slide=id.p
I can create this link manually by concatenating strings, but I can't figure out where the ID value comes from. Does anyone know?
UPDATE: So, I posted this question and went into the kitchen to eat. While I was eating it occurred to me that the difference isn't in the IDs of the files, it's in the file formats. When you open a PPT file in Google Slides, (I think) Drive converts the file to the Google Slides (.gslides) format before showing it. It uses the ID of the newly created file in the presentation link (second link above). If I put a .ppt file ID in the second link I get a "this file doesn't exist" error from Drive. If I put the ID of a .gslides file in the second link it opens in the Google Slides app as expected.
On your update, Nailed it. There is not a method to get presentation URL for a ppt or pptx document. If it was already a Google Slides document, then you would have access to the presentation URL via the metadata for that file.
I would like to add a 'file' to my drive which is simply a link to a website/page. I have tried creating a file with alternateLink and webContentLink fields specified but they just get overwritten.
I want to be able to store the link in Drive, retrieve it and use it in my app at a later date.
You can but not like that. You can:
1) write your own custom file and store the link as file data
2) additionally if you want the link to open from drive you can (unlike a comment in this question that saus you cant) by writting a Drive app and handle the file-open. See https://support.google.com/drive/answer/2500820?hl=en
What I was looking for was the 'shortcut' mimetype : "application/vnd.google-apps.drive-sdk", as described in create_a_shortcut_to_a_file. When I create a file with that mimeType, the alternateLink does not get overwritten. A 'file' is created in my drive and I can use the alternateLink to navigate to tghe page.
I'm looking for a way to either:
a) replace "File" > "Download as..." > "Microsoft Excel (.xlsx)" in Google Spreadsheet in such a way that when I click on "Microsoft Excel (.xlsx)" it asks me for the name of the file that I want to save (i.e.: like a typical "Save as..." menu entry).
b) if it's not possible to replace the standard menu entry, I would like at least to add another menu entry in another menu which behaves like described above.
Even though I haven't been able to write a script that lets me replace an existing menu entry, I've managed to write a script that adds an additional menu.
Is it possible to accomplish "a"?
Another problem now is that I can't seem to find a way to replicate the behaviour of "File" > "Download as..." > "Microsoft Excel (.xlsx)".
I've found other posts in which it's described how to write Google Scripts in order to do something similar (e.g.: create a backup of a spreadsheet in Google Drive in a specific format, or send it via GMail to a specific address).
Actually, after reading "Can I download file from URL link generated by google apps script" I'm not even sure it's possible.
Note that you cannot download per se, since you have no access to your
PC's resources (e.g. file system) from apps-script. The file is still
in "the cloud"... in this case, it's been copied from the web site it
was on, into Google Drive. If you're running the Drive app, though,
the file will now sync to your PC.
Is there any way to do that?
Thanks in advance.
The only way I achieved download of a file from the spreadsheet is by writing completely separate script which accessed my original spreadsheet by document id, generated a file and downloaded it like this:
function doGet(){
var outputDocument = DocumentApp.create('Some csv');
var content = getCsv();
var textContent = ContentService.createTextOutput(content);
textContent.setMimeType(ContentService.MimeType.CSV);
textContent.downloadAsFile("4NocniMaraton.csv");
return textContent;
}
Then I had to publish the App and get a link for it. That link I placed in one of the sheets in the original spreadsheet, which I used as a data download link. Other then this I didn't find a way to work the security issues around.