|
Hi I want to post "events" to my DAViCal using .ICS file and PHP/CURL. Below is my code and seems like something wrong with it. Or is there any other way to push events using .ICS to DAViCal? Thanks. $url = "http://my.davical.location/caldav.php/myusername/home/"; $ch = curl_init(); $localfile = "/my/ics/file/location/test.ics"; $fp = fopen ($localfile, "r"); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERPWD, 'myname:mypwd'); curl_setopt($ch, CURLOPT_HTTPHEADER, $header_array); curl_setopt($ch, CURLOPT_PUT, 1); curl_setopt($ch, CURLOPT_UPLOAD, 1); curl_setopt($ch, CURLOPT_REFERER, 1); curl_setopt($ch, CURLOPT_INFILE, $fp); curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile)); curl_exec($ch); |
|
On Fri, 2010-07-09 at 14:44 -0700, Coolrugs wrote:
> > Hi I want to post "events" to my DAViCal using .ICS file and PHP/CURL. > Below is my code and seems like something wrong with it. > > Or is there any other way to push events using .ICS to DAViCal? > > Thanks. > > $url = "http://my.davical.location/caldav.php/myusername/home/"; > $ch = curl_init(); > $localfile = "/my/ics/file/location/test.ics"; > $fp = fopen ($localfile, "r"); > curl_setopt($ch, CURLOPT_URL, $url); > curl_setopt($ch, CURLOPT_USERPWD, 'myname:mypwd'); > curl_setopt($ch, CURLOPT_HTTPHEADER, $header_array); > curl_setopt($ch, CURLOPT_PUT, 1); > curl_setopt($ch, CURLOPT_UPLOAD, 1); > curl_setopt($ch, CURLOPT_REFERER, 1); > curl_setopt($ch, CURLOPT_INFILE, $fp); > curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile)); > curl_exec($ch); This seems to be on the right track. What's the content of $header_array ? Having a CURLOPT_PUT seems a strange way to set the method though. Is the library really that broken, or can you just specify the method by name, somehow? How would one specify more obscure methods such as MKCALENDAR, BIND or DELTICKET, for example? DAViCal doesn't check the referrer header, and I'm not sure if CURLOPT_UPLOAD is needed in this case - you might want to check that one. Cheers, Andrew. -- ------------------------------------------------------------------------ andrew (AT) morphoss (DOT) com +64(272)DEBIAN Wagner's music is better than it sounds. -- Mark Twain ------------------------------------------------------------------------ ------------------------------------------------------------------------------ This SF.net email is sponsored by Sprint What will you do first with EVO, the first 4G phone? Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first _______________________________________________ rscds-general mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/rscds-general |
|
Hi Andrew,
Thanks for your reply, however I tried different combination and removing $header_array, CURLOPT_PUT, CURLOPT_UPLOAD and CURLOPT_REFERER but it didn't work. But I was able to use this: curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, 'MKCALENDAR'); and successfully I was able to create new calendar. So I tried playing around "curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, 'PUT');", hoping that I can write .ICS thru 'PUT' but it was not successfull. $url = "http://my.davical.location/caldav.php/myusername/home/"; $ch = curl_init(); $localfile = "/my/ics/file/location/test.ics"; $fp = fopen ($localfile, "r"); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERPWD, 'myname:mypwd'); curl_setopt($ch, CURLOPT_INFILE, $fp); curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile)); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); $response = curl_exec($ch); print_r($ch); print_r($response); SCREEN IS OUTPUT = "Resource id #371" Any help on using 'PUT' and import .ICS is highly appreciated. Thanks... |
|
On Mon, 12 Jul 2010 13:02:15 -0700 (PDT)
Coolrugs <[hidden email]> wrote: > > $url = "http://my.davical.location/caldav.php/myusername/home/"; Your problems are here. The URL must contain a unique local URI. A solution could be: $filename = $url . sha1(date('U')) . sha1_file($localfile) . '.ics'; > curl_setopt($ch, CURLOPT_URL, $url); And then replace: curl_setopt($ch, CURLOPT_URL, $url); with curl_setopt($ch, CURLOPT_URL, $filename); > curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); > Also using CURLOPT_CUSTOMREQUEST is not required. Using the above with: curl_setopt($ch, CURLOPT_PUT, 1); is sufficient. -- Hilsen/Regards Michael Rasmussen Get my public GnuPG keys: michael <at> rasmussen <dot> cc http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xD3C9A00E mir <at> datanom <dot> net http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xE501F51C mir <at> miras <dot> org http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xE3E80917 -------------------------------------------------------------- Make sure special cases are truly special. - The Elements of Programming Style (Kernighan & Plaugher) ------------------------------------------------------------------------------ This SF.net email is sponsored by Sprint What will you do first with EVO, the first 4G phone? Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first _______________________________________________ rscds-general mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/rscds-general |
|
In reply to this post by Coolrugs
On Mon, 2010-07-12 at 13:02 -0700, Coolrugs wrote:
> Hi Andrew, > > Thanks for your reply, however I tried different combination and removing > $header_array, CURLOPT_PUT, CURLOPT_UPLOAD and CURLOPT_REFERER but it > didn't work. > > But I was able to use this: > curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, 'MKCALENDAR'); > and successfully I was able to create new calendar. > > So I tried playing around "curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, > 'PUT');", hoping that I can write .ICS thru 'PUT' but it was not > successfull. > > $url = "http://my.davical.location/caldav.php/myusername/home/"; > $ch = curl_init(); > $localfile = "/my/ics/file/location/test.ics"; > $fp = fopen ($localfile, "r"); > curl_setopt($ch, CURLOPT_URL, $url); > curl_setopt($ch, CURLOPT_USERPWD, 'myname:mypwd'); > curl_setopt($ch, CURLOPT_INFILE, $fp); > curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile)); > curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); > $response = curl_exec($ch); > print_r($ch); > print_r($response); > > SCREEN IS OUTPUT = "Resource id #371" > > Any help on using 'PUT' and import .ICS is highly appreciated. the "Content-type" header on your request. It should be set to 'text/icalendar'. Good to know that you *can* do custom requests though :-) Cheers, Andrew. -- ------------------------------------------------------------------------ andrew (AT) morphoss (DOT) com +64(272)DEBIAN Open Source: the difference between trust and antitrust ------------------------------------------------------------------------ ------------------------------------------------------------------------------ This SF.net email is sponsored by Sprint What will you do first with EVO, the first 4G phone? Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first _______________________________________________ rscds-general mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/rscds-general |
|
Finally! This works...
Thanks Andrew & Michael. @Andrew, I will try all custom request "caldav.php=>$request->method". I decided to use CURL because I can't get "$request->method['PUT']" worked. $url = "http://my.davical.location/caldav.php/myusername/home/"; $localfile = "/my/ics/file/location/test.ics"; $filename = $url.sha1(date('U')).sha1_file($localfile).'.ics'; $header_array = array("Cache-Control: no-cache", "Content-type: text/icalendar"); $fp = fopen ($localfile, "r"); $ch = curl_init(); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_URL, $filename ); curl_setopt($ch, CURLOPT_USERPWD, "myname:mypwd"); curl_setopt($ch, CURLOPT_HTTPHEADER, $header_array); curl_setopt($ch, CURLOPT_UPLOAD, 1); curl_setopt($ch, CURLOPT_PUT, 1); curl_setopt($ch, CURLOPT_INFILE, $fp); curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile)); curl_exec($ch); curl_close($ch); fclose($fp); |
|
In reply to this post by Andrew McMillan
Hi Andrew,
Just downloaded davical-0.9.9, and at /davical-0.9.9/htdocs/caldav.php line #67 "case 'text/calendar':", does it matter between 'text/icalendar' as you had mentioned? Thanks... |
|
On Tue, 2010-07-13 at 08:53 -0700, Coolrugs wrote:
> Hi Andrew, > > Just downloaded davical-0.9.9, and at /davical-0.9.9/htdocs/caldav.php > line #67 "case 'text/calendar':", does it matter between 'text/icalendar' as > you had mentioned? Sorry - I was running from memory, as fallibly as ever, I'm afraid. If you read 'text/calendar' in the code that is the correct mime type. Cheers, Andrew. -- ------------------------------------------------------------------------ andrew (AT) morphoss (DOT) com +64(272)DEBIAN It's all in the mind, ya know. ------------------------------------------------------------------------ ------------------------------------------------------------------------------ This SF.net email is sponsored by Sprint What will you do first with EVO, the first 4G phone? Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first _______________________________________________ rscds-general mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/rscds-general |
|
Thanks Andrew. I got my PHP->CURL + DAViCal works!
However, I had some concerned. I had a Drag-Drop Calendar (JQuery+PHP+MySQL) base. And since I already had DAViCal works on my server I want to store all events to DAViCal DB (which is PostgreSQL). So instead of writing PostgreSQL Query (that includes converting my existing MySQL Queries to PG), I did use PHP CURL which works fine (so meaning "NO" PG & MySQL Query). Now the issue is, on Drop event I only need to update the "dtstart" and "dtend" date. To do this I need the following: 1. GET event from DAViCal. (.ICS output) 2. Change the "dtstart" and "dtend" by manipulating that (.ICS output) 3. POST it back to DAViCal. (looks like creating another .ICS) Does anybody had suggestion or shortcuts to this? I would like to avoid writing/creating an .ICS file. Thanks in advance. |
| Powered by Nabble | Edit this page |
