how to get specific items data from google calendar api

Viewed 50

hi I am using google api to get all the events which is working fine. There is a parameter where I can specify fields name which I need to retrieve. There is a filed named as items where all the events data are coming. Now I want to get specific data of that items filed. Not all the data.

This is how I am getting all the data of that items.

https://www.googleapis.com/calendar/v3/calendars/CALENDAR_ID/events?showDeleted=true&timeMax=2021-08-16T06%3A00%3A46.000Z&timeMin=2021-04-16T06%3A00%3A46.000Z&prettyPrint=true&fields=items&key=[YOUR_API_KEY]

This is how data are coming.

{
"items": [
{
"kind": "calendar#event",
"etag": "\"hfsfjadj\"",
"id": "adfjadfjad",
"status": "confirmed",
"htmlLink": "https://www.google.com/calendar/event?eid=adfjdafjd",
"created": "2021-05-24T05:47:42.000Z",
"updated": "2021-05-24T05:47:42.331Z",
"summary": "dafhafj",
"creator": {
"email": "adfjadfj@gmail.com",
"self": true
},
"organizer": {
"email": "adfjadfj@gmail.com",
"self": true
},
"start": {
 "dateTime": "2021-05-24T11:30:00+06:00"
},
"end": {
 "dateTime": "2021-05-24T12:30:00+06:00"
},
"iCalUID": "dfjdfjdfj@google.com",
"sequence": 0,
"reminders": {
 "useDefault": true
},
"eventType": "default"
}
]
}

I wanted to fetch only id, start,end and summary not the entire thing which is given above.

1 Answers

You can specify nested fields by enclosing them in round brackets, and multiple fields should be separated by commas. Your provided fields would be something like this:

items(id,start,end,summary)

Therefore, the URL would change from this:

https://www.googleapis.com/calendar/v3/calendars/CALENDAR_ID/events?showDeleted=true&timeMax=2021-08-16T06%3A00%3A46.000Z&timeMin=2021-04-16T06%3A00%3A46.000Z&prettyPrint=true&fields=items&key=[YOUR_API_KEY]

To this:

https://www.googleapis.com/calendar/v3/calendars/CALENDAR_ID/events?showDeleted=true&timeMax=2021-08-16T06%3A00%3A46.000Z&timeMin=2021-04-16T06%3A00%3A46.000Z&prettyPrint=true&fields=items(id%2Cstart%2Cend%2Csummary)&key=[YOUR_API_KEY]

Reference:

Related