OAuth2/Google CalDAV - List of calendars for user

1.7k Views Asked by At

I used to request caldav servers to give all defined calendars for a given user. That works with fruux/ownCloud(Sabre) and also GCalendar the classic method. The request is this:

method: PROPFIND  headers:Depth: 1  
urlstr:https://www.google.com/calendar/dav/{theUserName}@gmail.com/  
contentType:application/xml  
content:
<d:propfind xmlns:d="DAV:" xmlns:cs="http://calendarserver.org/ns/" xmlns:c="urn:ietf:params:xml:ns:caldav">  
  <d:prop>  
    <d:resourcetype />  
    <d:displayname />  
    <cs:getctag />  
    <c:supported-calendar-component-set />  
  </d:prop>  
</d:propfind>  

Moving to Google OAuth2 has different calls, the ulrstr: would something like https://apidata.googleusercontent.com/caldav/v2/{calid}/user
Here the 'calid' has to be a specific calendar [1] There iis said:

Where calid should be replaced by the "calendar ID" of the calendar to be accessed

The intension is to get all calendars for a user's account! So those calls will NOT help.

Any suggestion how to get them in the Google/CalDAV/V2 world?

Günter

See also: [1] https://developers.google.com/google-apps/calendar/caldav/v2/guide

1

There are 1 best solutions below

0
On

The link in the answer's comment is broken. So I wrote a working answer here.

  1. Find current user's principal using PROPFIND.
PROPFIND https://apidata.googleusercontent.com/caldav/v2

<?xml version="1.0" encoding="utf-8" ?>
<D:propfind xmlns:D="DAV:">
    <D:prop>
        <D:current-user-principal/>
    </D:prop>
</D:propfind>

2.PROPFIND calendar-home-set with the principal URL we got in the above request's response.

PROPFIND https://apidata.googleusercontent.com/{user-principal-path}

<?xml version="1.0" encoding="utf-8" ?>
<D:propfind xmlns:D="DAV:">
     <D:prop>
       <C:calendar-home-set xmlns:C="urn:ietf:params:xml:ns:caldav"/>
     </D:prop>
</D:propfind>

cf) Another way of finding the calendar-home-set using REPORT principal-match didn't work in my case.

  1. PROPFIND calendar-home-set with Depth header value 1.
PROPFIND https://apidata.googleusercontent.com/{calendar-home-set-path}
Depth: 1

<?xml version="1.0" encoding="utf-8" ?>
<D:propfind xmlns:D="DAV:"
            xmlns:C="urn:ietf:params:xml:ns:caldav">
     <D:prop>
        <D:displayname/>
        <D:resourcetype/>
        <C:supported-calendar-component-set/>
     </D:prop>
</D:propfind>