How I can read the contents of text file using google drive api v3 - google-drive-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

Related

Is it possible to upload an entire folder to Google Drive using Google Drive API?

I am currently exploring Google Drive APIs and am able to upload an individual file using Postman successfully.
I tried to create/upload a folder using Google Drive API but failed. In fact, I don't see any specific API to deal with a folder. I was giving it a try with create files API.
Reference - https://developers.google.com/drive/api/v3/reference
Any help will be appreciated.
If you check the documentation for files.create you will notice at the top it states
Creates a file.
This is singular each request creates a single file. If you want to upload a directory you will need to first create the directory then upload each file one at a time.
You could try batching but I don't think you can batch the file upload itself you could probably batch the metadata creation performance#details

Google Drive Url System Design

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

Move file from appDataFolder to user's root folder with Google drive API

Is it possible to move file from appDataFolder to user's root folder on Google Drive using drive API v2 or v3? I can't find any example how to do that. I just try to use gapi.client.drive.files.update from javascript drive v3 API and addParents parameter to change folder, it works fine with files in user's root folder, but doesn't work with files in appDataFolder.
I know that it is possible to copy file from appDataFolder to user's drive root, but I need to keep fileId, and copying generates new fileId for copied file.
I found there is a file property called "spaces" and files from appDataFolder a in spaces=appDataFolder whereas files from user's root folder are in spaces=drive. Is it possible to move file between these spaces keeping same fileId?
I found some similar posts:
Copy an exising Drive file into the appdata folder
Is it possible to share the application data on google drive
and it looks like it is not possible to do it this way. When I check my console I also get "Method not supported for appdata contents" or "Method not supported for files within the Application Data folder." message.
So is there any method to move file from appDataFolder?
Thank's for help.
No, it seems to be impossible. The current document doesn't mention about that, but the error message clearly says so. Thumb down for drive api.

Google Docs document format?

What I'd like to accomplish: Download a Google Docs doc (with Google Drive API), modify it (for example highlight some text), then store it back to Google Drive (not messing up the format, so that it can be edited in the Google Docs app).
(Preemptive research: I know that you can do some integration with Google's hosted AppScript, but I want to do this offline. I also know that a Google Docs doc can be exported to other formats, but I see no sign of reimporting in the Google Drive API.)
I'm not hopeful this can be done:
* The meta-data file (that you can get via the Google Drive API) lacks a "downloadUrl" attribute
* In offline mode, the data (stored in .../File System/) is binary and the Unix "file " command doesn't know what format it is.
Is this off-limits with the current Google Drive API?
Your best (only) approach is to export the doc to a format that you can edit locally (html, docs, etc) and then reimport it. HTML is of course the easiest, but also the most lossy.

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.