I have created a service account in google drive for uploading files in google drive from server and download those files later. But when I tried to get list of files of a folder and get the webContentLinks
of those file, it returned null. I checked it for some other properties, it returns null for both getWebContentLink()
and getWebViewLink()
except the file name and file id.
Can anyone help me to get the webContentLink
or can you figure out the issue about why I cant get webContentLink
.
Here is a part of code I tried:
List<String> linkList=new ArrayList<String>();
fileFlag=0;
pageToken = null;
do {
driveFiles = service.files().list()
.setQ("mimeType!='application/vnd.google-apps.folder and "+childFolder.getId()+"' in parents ")
.setSpaces("drive")
.setFields("nextPageToken, files(id, name)")
.setPageToken(pageToken)
.execute();
System.out.println("\n\nFile No. : "+driveFiles.getFiles().size());
for(com.google.api.services.drive.model.File file: driveFiles.getFiles()) {
linkList.add(file.getWebContentLink());
System.out.println(file.getName());
System.out.println("File Link : "+file.getWebContentLink());
System.out.println(file.getId());
System.out.println(file.getWebViewLink());
}
pageToken = driveFiles.getNextPageToken();
} while (pageToken != null);
Here is one of the Output
File No. : 4
V2__data.sql
File Link : null
0BzCRyzakN8eJOGRTODhXTFkxUWc
null
V1__table.sql
File Link : null
0BzCRyzakN8eJT09BbG5JUFdNYmc
null
V2__data.sql
File Link : null
0BzCRyzakN8eJa0FyUGw3UFZJZ00
null
V1__table.sql
File Link : null
0BzCRyzakN8eJcDJNWHY4cFNHMW8
null