Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I use this library to list the events in a calendar? #68

Closed
mpenkov opened this issue Apr 18, 2022 · 5 comments
Closed

How do I use this library to list the events in a calendar? #68

mpenkov opened this issue Apr 18, 2022 · 5 comments

Comments

@mpenkov
Copy link

mpenkov commented Apr 18, 2022

Hi, I'm trying to list the events in my calendar using your library. I've managed to get as far as the list of calendars, but I can't seem to get to the actual events. Can you please have a look and let me know what I'm doing wrong?

package main

import (
	"fmt"
	"log"
	"net/http"

	gowebdav "github.com/emersion/go-webdav"
	"github.com/emersion/go-webdav/caldav"
)

func main() {
	fmt.Println("hello world!")

	httpClient := &http.Client{}
	authorizedClient := gowebdav.HTTPClientWithBasicAuth(httpClient, "USERNAME", "PASSWORD")  // FIXME

	caldavClient, err := caldav.NewClient(authorizedClient, "https://caldav.fastmail.com/dav/calendars/user/USERNAME")
	if err != nil {
		log.Fatalf("NewClient: %s", err)
	}

	// curl -X PROPFIND -u USERNAME:PASSWORD https://caldav.fastmail.com/dav/principals/user/USERNAME
	homeSet, err := caldavClient.FindCalendarHomeSet("/dav/principals/user/USERNAME")
	if err != nil {
		log.Fatalf("FindCalendarHomeSet: %s", err)
	}

	fmt.Println(homeSet)

	calendars, err := caldavClient.FindCalendars(homeSet)
	if err != nil {
		log.Fatalf("FindCalendars: %s", err)
	}
	for i, calendar := range calendars {
		fmt.Printf("cal %d: %s %s\n", i, calendar.Name, calendar.Path)
	}

	compRequest := caldav.CalendarCompRequest{
		Name: "VEVENT",
		AllProps: true,
		AllComps: true,
	}
	compFilter := caldav.CompFilter{}
	query := caldav.CalendarQuery{CompRequest: compRequest, CompFilter: compFilter}
	objects, err := caldavClient.QueryCalendar(calendars[3].Path, &query)
	if err != nil {
		log.Fatalf("QueryCalendar: %s", err)
	}

	for i, obj := range objects {
		fmt.Printf("%d %s", i, obj.Path)
	}
}

I'm getting this error:

2022/04/18 13:21:01 QueryCalendar: 400 Bad Request: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <title>400 Bad Request</title>
  </head>
  <body>
    <h1>Bad Request</h1>
    <p>The request was not understood by this server.</p>
    <hr>
    <address>Cyrus-HTTP/3.7.0-alpha0-387-g7ea99c4045-fm-20220413.002-g7ea99c40 Cyrus-SASL/2.1.27 Lib/XML2.9.10 Jansson/2.13.1 OpenSSL/1.1.1n Wslay/1.1.1 Zlib/1.2.11 Brotli/1.0.9 Xapian/1.5.0 LibiCal/3.0 ICU4C/69.1 SQLite/3.34.1 Server at caldav.fastmail.com Port 2275</address>
  </body>
</html>
exit status 1

Also, if there are any docs/tutorials on using your library?

@emersion
Copy link
Owner

Sorry, this issue tracker is for bug reports or feature requests, not questions.

@ptrcnull
Copy link

ptrcnull commented Nov 8, 2022

Sorry, this issue tracker is for bug reports or feature requests, not questions.

@emersion i would consider this an issue of insufficient documentation; even after reading the RFCs for both WebDAV and CalDAV, it's unclear how the library handles serialization of CalendarCompRequest and CompFilter

@jtagcat
Copy link

jtagcat commented Oct 7, 2023

For anyone else looking, https://github.com/jtagcat/redacted-caldav getCalendar()

@encima
Copy link

encima commented Oct 13, 2023

@emersion Working on an OSS library is a huge effort and massive thank you for doing it. Closing issues like this one without providing a place to ask these questions, or linking to a solutin, does indicate that this is an issue (even if that issue is not with your target userbase).
I would suggest allowing Github Discussions for these things or providing a Code of Conduct that explains what Issues are used for.

@mpenkov
Copy link
Author

mpenkov commented Jul 8, 2024

Finally got it working: https://github.com/mpenkov/tools/blob/master/fmc/main.go

Thank you everyone for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants