I am working on an Android project and I am trying to make use of the Google Drive API and I've got most of it working but I am having an issue in how I perform a download.
I can't find anywhere how I get the file ID so that I can perform the download. In order to test I've retrieved all files in my drive account and added them to a list array and then got the ID for the first file in the list.
I then copied the file ID in to the command to download the file and this worked successfully but I have no idea how to get the file id of the specific file I want to download.
Below is the code I am using to download the file.
private void downloadFile() { Thread thread = new Thread(new Runnable() { @Override public void run() { try { com.google.api.services.drive.model.File file = service.files().get("0B-Iak7O9SfIpYk9zTjZvY2xreVU").execute(); //FileList file = service.files().list().execute(); //List<com.google.api.services.drive.model.File> fileList = file.getItems(); //com.google.api.services.drive.model.File fileItem = fileList.get(0); //Log.d("FileID" , fileItem.getId()); //Log.d("Count", "Retreived file list"); if (file.getDownloadUrl() != null && file.getDownloadUrl().length() > 0) { HttpResponse resp = service.getRequestFactory().buildGetRequest(new GenericUrl(file.getDownloadUrl())).execute(); InputStream inputStream = resp.getContent(); writeToFile(inputStream); } } catch (IOException e) { Log.e("WriteToFile", e.toString()); e.printStackTrace(); } } }); thread.start(); }
0B-Iak7O9SfIpYk9zTjZvY2xreVU
is the file ID of the file that I download which I retrieved when I did a list and selected the first file, but how can I say I want to download, File_1 and get its ID to then pass this to the service.get().execute function.
Basically my end goal is within my app, I upload an XML file to Google Drive, and then later on Download the file. It will only be one file and will always have the same name. Am I going about it the right away or is there a better way to achieve what I am trying to do?
In my opinion the easiest and fastest way to get a Google Drive file ID is from Google Drive on the web. Right-click the file name and select Get shareable link. The last part of the link is the file ID.
Getting this folder ID is easy, navigate to https://drive.google.com and make a folder. After you did this, open up the folder and check the URL: Grab this ID and enter it inside the 'Folder ID's' inside the modal to specify that the backup has to be put in that folder.
By default, viewers can download, copy and print attachments. According to your library permissions, you can prevent viewers from managing attachments. Note: Library administrators can also prevent users from duplicating documents.
The document id is not the URL of the document, but it is a UID generated when the document is created, e.g., it is the value of id after var id = createDocWithTable("doc with table") .
In my opinion the easiest and fastest way to get a Google Drive file ID is from Google Drive on the web. Right-click the file name and select Get shareable link. The last part of the link is the file ID. Then you can cancel the sharing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With