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.
Related
Using the Google Drive API I can get a file's webViewLink to link to the file-preview in Drive, and the user can then select 'Open with Google Sheets' in the top bar to open the file up in Sheets.
Is there a way to skip that intermediary step, and link directly to that file in Google Sheets?
File.resource also contains a link called webViewLink
webViewLink string A link for opening the file in a relevant Google editor or viewer in a browser.
This will not work on all file types but it should work on sheets.
What are you seeing in webViewLink?
When I try, I get
"webViewLink": https://docs.google.com/spreadsheets/d/1egZQnArX7TOHlQWSHiba3TTNt9Y7JoqgDAIJMdM0MQ/edit?usp=drivesdk"
which directly opens the sheet.
So a couple of things:-
Are you sure that the file in question is a native Google spreadsheet, or is it, for example, an uploaded Excel
If your webViewLink is different, you could construct the URL yourself by setting your own file's ID after the /d/
I noticed this behavior on Google Drive.
When a link is created for a file on Google Drive, the link is valid until the file is deleted.
Moving the file to another folder(s) does not affect the behavior of url.
I will like to understand how they achieved this at scale.
This is an expected behavior when moving files to another folder within your google drive. This is because a google file URL is usually composed of the following:
product domain
product
document Id
Therefore, moving the file to another folder within the google drive will not affect the file URL because file path is not included in the URL format.
References:
Google Sheets API Overview
Docs API
I would like to build an application on a webpage, that does as google docs:
I want to build an app that allow people to work on a document in collaboration
I start with this: https://developers.google.com/drive/realtime/realtime-quickstart
But the problem is that it creates a file with the mimetype is "application/vnd.google-apps.drive-sdk".
I would like to work with google docs format, so people can open them with their google drive and edit their later.
The file created is not the proper format, and find it me impossible to open it.
( I try to edit the mimetype with "application/vnd.google-apps.document", however it creates the file in the google drive but it can't find the file when it try to load it).
How to create a google doc in realtime ? (If you can post the code here, it would help me a lot)
Then, it want to add the toolbar for editing(bold, italic,...).
After that, it would like to add the google picker to select the file to load.
Is it possible to create a new document (either using a template or completely dynamic) using the Google Drive APIs? I am working with a client that requires generation of word documents. I tired looking up but I couldn't find sufficient documentation on how to "create and format" documents using the APIs.
For example, can I include the client's company logo on the top of the doc programmatically? I'd like whatever I am doing for this client to be generic (i.e including logo at the top etc) to be dynamic, so I can re-purpose this for other clients as well.
I also am having difficulty finding documentation on any kind of formatting we could do on the documents (bold, italic, new paragraph) etc
The Google Drive API only deals with whole file operations. It has no understanding of the content of the files, including formatting.
You have two options:-
Use Apps Script (ie. not the Drive API) which has document manipulation features. See https://developers.google.com/apps-script/reference/document/
Create your templates in HTML (or Word, OpenOffice), then upload them to a new file, setting the option to 'convert to google docs'
It is possible to create new documents as well as make a copy of already existing documents (templates)
Some time ago I've created simple example how to work with templates:
On your Google drive create folder Templates
Inside this folder create formated document with images, texts etc... Replace dynamic values with {A},{B},{C} representing spreadsheet column names in this document
Than create spreadsheet and fill some data in it. Inside this spreadsheet navigate to Tools->Script gallery and search for fast template generator -> Install it
Close document and re-open it. Script will automatically execute onOpen function which will add Template generator to spreadsheet menu. Now just choose row from which you would like to populate values in template and launch Template generator-> Generate from template.
A new document with filled values will be generated from chosen template.
You can find source code and customize it in according your need in Tools->Script editor in this spreadsheet, so result should be in PDF or sent via email etc...
EDIT: Seems this approach does not work, as Google Drive API only allows copying files across current user's Drive.
I found for me suitable approach was to create a document in my own Google Drive. Style it accordingly, add base text etc. and give it read-only permission to everyone. Then from the Google Drive API use copy file functionality and copy it into the current users Drive.
I have an interesting fairly simple problem I am trying to solve but I am at a loss on the proper code to get this to working correctly.
Basically, I have an very old local application running which allow me to print a receipt of a transaction. I have the ability to enable this receipt to be printed to a specific file within a specific directory on my computer or I can set it up to print out automatically to a printer on my computer. Currently I print the data out to a file, then copy the contents of that file and paste it into a word document template and then manually go through and format the data so it looks clean (I should note that the data prints out in fixed field format requiring a specific font and size so its pasts correctly. After all this is done I then email the word or pdf document out.
Essentially what I am trying to do here is automate this method and I thought this should be possible using a Google Apps Script.
My thought here was that it should be possible to:
save all the original files from my application to a specific
directory on my computer
sync that folder with google drive
have a google apps script automatically execute upon upload
have the google apps script automatically use a specific document
template I create with a header/footer and then paste all the
contents from the new file which was uploaded
have the google apps script pattern match certain elements within the contents of
the document and properly format it.
save the document to a specific location with a specific file naming convention
automatically email the document as a doc or pdf based upon a
specific regex matched field within the source document.
Could anyone provide a specific code example which demonstrates how Google apps scripts can be utilized to monitor the contents of a specific Google drive folder to trigger an event immediately after a new file is uploaded?
Thanks in advance!