Google tasks API. What parameters to use in TasksRequest.setFields(String fields) method?
-
20-06-2021 - |
Question
I'm building a Android app that sync tasks to google tasks. And i used the Google Tasks APIs. My question is what parameters can I use in TasksRequest.setFields(String fields)? I see the sample code uses "items/title". What if i want to get other fields or what if i want to get multiple fields at the same time?
Solution
The format of this string is described here: https://developers.google.com/discovery/v1/performance#partial-response
And the APIs Explorer can help you build the string as well using a UI: https://developers.google.com/apis-explorer
OTHER TIPS
You must be referring to this snippet of code from the Google Tasks API sample for Android:
@Override
protected List<String> doInBackground(Void... arg0) {
try {
List<String> result = new ArrayList<String>();
com.google.api.services.tasks.Tasks.TasksOperations.List listRequest = service.tasks().list("@default");
listRequest.setFields("items/title,items/notes,items/completed");
//listRequest.setFields("items/title");
List<Task> tasks = listRequest.execute().getItems();
if (tasks != null) {
for (Task task : tasks) {
result.add(task.getTitle());
}
} else {
result.add("No tasks.");
}
return result;
} catch (IOException e) {
tasksSample.handleGoogleException(e);
return Collections.singletonList(e.getMessage());
} finally {
tasksSample.onRequestCompleted();
}
}
The documentation is very unclear about this, but this link gave me a clue.
Notice that I use
"items/title,items/notes,items/completed"
If you get the strings wrong, you will get
invalidParameter and Invalid field selection note