How to create new file and open in Google Docs editor? - google-drive-api

Is it possible to create a new Google Docs document, and then open it in the Google Docs editor? We have documents in our site that would be great to upload to Google Docs for editing but I'm having trouble figuring out if that's possible between the deprecated docs list API, and the new Google Drive API. Thanks.

Yes.
When you upload a file you will get back an item resource which contains a field AlternateLink. This is the edit URL.
To try it, go to https://developers.google.com/drive/v2/reference/files/get#try-it, click Oauth to On, then paste one of your file IDs into the fileId field. When you get back the item resource, just click the AlternateLink

Related

How to link to a Google drive file? [duplicate]

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/

Unable to get the ID of opened .docx file in Docs Add-on

I am stuck at getting the ID of the .docx file inside Google Docs Add-on.
The Id is present in the URL of the browser but I am unable to find any method to get the browser URL.
The method DocumentApp.getActiveDocument().getId() is not helping because it works on Google Docs file, and the file that I open in Google doc is Microsoft Word Format (.docx) file.
I am attaching a screenshot for reference: Reference image
Is there any way to get the ID of .docx file inside Google Docs Add-on?
Or is there any way to get the URL of the browser when the .docx is opened in the Google Docs Add-on?
Thanks in advance.
Answer:
There's no way to retrieve this information for non-Google Docs in Workspace add-ons.
Explanation:
As you mentioned, DocumentApp methods only work for Google Docs files.
Also, the Workspace add-on's Docs event object is only populated if the current document is a Google Docs. I just checked that's the case.
Finally, this information is not retrievable in the context of Workspace add-ons.
Feature request:
You could consider filing a feature request using this Issue Tracker template if you think this functionality could be useful.
Check out the event object for Workspace Addons using this link. When you build your card, you have access to the event. So you should be able to access it using docs.id within your function.

Is it possible to covert Word docs to a Google Doc?

I am uploading Word documents to Google Drive using the Google SDK. I can view these files once uploaded through the Google Drive interface, but to edit these documents I need to selected "Open with Google Docs". When I do this, Google makes another version of the file and saves it to my Google Drive.
I want to automatically create a URL for users to click on once their file has been uploaded, so I presume I somehow need to convert the uploaded file (Word Document) to a Google Docs file so a user can then edit it and save it. Is this possible?
You need to send the optional query parameter of convert
convert (boolean) Whether to convert this file to the corresponding
Google Docs format. (Default: false)
Documentation for Google Drive Insert

Google Realtime API with Google Docs

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.

edit link from google drive api

While I get a file object from google drive api, I want to get the link to edit this file with google docs interface.
But as defined here, I only get the link to google docs if the drive.apps.readonly scope is set to readonly.
Is there any way to get this link for editing?
You should actually use drive.apps.readonly scope. "readonly" means that you cannot edit installed google apps, but you still can get list of these apps, and open any document for editing.