Reputation: 13
I am working with Android Quickstart for Google Drive Rest APi provided at the below link. Android Quickstart
The sample code works fine as is. However when I try to get other details from files like getCreatedTime()
or GetWevViewLink()
'null' is returned. Only getName() and getId() returns values.
Upvotes: 1
Views: 1424
Reputation: 2662
Google Drive REST APIs v3 would only return only certain default fields. If you need some field, you have to explicitly request it by setting it with .setFields()
method.
Modify your code like this -
private List<String> getDataFromApi() throws IOException {
// Get a list of up to 10 files.
List<String> fileInfo = new ArrayList<String>();
FileList result = mService.files().list()
.setPageSize(10)
// see createdTime added to list of requested fields
.setFields("nextPageToken, files(createdTime,id,name)")
.execute();
List<File> files = result.getFiles();
if (files != null) {
for (File file : files) {
fileInfo.add(String.format("%s (%s)\n",
file.getName(), file.getId()));
}
}
return fileInfo;
}
You can read more about this behavior here https://developers.google.com/drive/v3/web/migration Updated link https://developers.google.com/drive/api/v2/migration
Quoting from the above link -
Notable changes
- Full resources are no longer returned by default. Use the fields query parameter to request specific fields to be returned. If left unspecified only a subset of commonly used fields are returned.
Accept the answer if it works for you so that others facing this issue might also get benefited.
Upvotes: 10
Reputation: 17613
I think you need to use the Metadata class to be able to use the getCreatedDate as indicated in Working with File and Folder Metadata.
Then try something like:
ResultCallback<MetadataResult> metadataRetrievedCallback = new
ResultCallback<MetadataResult>() {
@Override
public void onResult(MetadataResult result) {
if (!result.getStatus().isSuccess()) {
showMessage("Problem while trying to fetch metadata");
return;
}
//show the date when file was created
Metadata metadata = result.getMetadata();
showMessage("File was created on " + metadata.getCreatedDate() );
}
}
Upvotes: 0