My end goal is to write a simple program that downloads one specific Google spreadsheet at the end of each week to my local hard drive. The file will be edited on a week to week basis by other people, and I will constantly need to download the updated version to pull out data and pass to a bash script that I have written. I am now doing this manually, but if I can pull down the spreadsheet in a csv format, can automate the entire process.
I am slightly confused by Google's Documentation. I have copied their example method downloadFile
, but am still unclear about the exact parameters that are being passed, and the InputStream
return.
If I were to add a main method to call the downloadFile
method, what would be example parameters that I pass.
Then, can I use the InputPut
stream it returns to save the file is csv format?
Also, is this the only method I need or do is there more to it?
downloadFile
method is defined here (left out the import statements):
private static InputStream downloadFile (Drive service, File file) {
if (file.getDownloadUrl() !=null && file.getDownloadUrl().length() > 0) {
try {
HttpResponse resp = service.getRequestFactory().buildGetRequest(new GenericUrl(file.getDownloadUrl())).execute();
return resp.getContent();
}
catch (IOException e) {
e.printStackTrace();
return null;
}
}
else {
return null;
}
}