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.
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
For example we have a link to Google Drive: https://drive.google.com/file/d/1o4bqvKsGjf_yukzt-zQPtZWtqv21gpmv/view?usp=sharing
This file on someone's drive, not on my own. And how to download this file using API, if I know only a link?
The share with me link that you can get via the google drive web application. is not a true form of sharing.
In order to download a file using the api you must first have permission to access that file. That being said you must have a record on the file with your username (email address) returned by a premissions.list call on the file.
Without it when you do a file.list the file will not show up as you do not have permissions on the file.
The issue with the share with me link is that the Id is not the id of the file. So even if the file was public you would not be able to find it.
To be clear a share with me link to a file on google drive does
not contain the true file id needed for the api
grant any true permissions on the file. meaning that you cant access it via the api.
I tried to use Get(). I was able to read/update the file metadata but don't know how to get the file contents. From my googling I know I have to identify alt=media but I don't know how. Could anybody give a full example.
To retrieve the contents of a Gogle document like Google Sheets, Google Docs etc. you can use the Sheets API, Docs API etc. respectively
To retrieve the contents of a non-Google file on your Google Drive, like e.g. a text file - you cannot do it directly
Instead, you need to donwload the file to your local Drive
For this, when using the method Files: get, specify alt=media as you already know
However, this will not directly give you the file contents, but rather request a download of the contents from the server
In the next step you need to write this downloaded content to a file on your local machine
The Guide for downloading files stored on Google Drive provide samples of how to do so in Java, Python and Node.js
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.