0

I'm trying to get list of Yahoo calendars using the next code.

$url = "https://calendar.yahoo.com/";
$user = "****@yahoo.com";
$pwd = "*****";
$body = "<A:propfind xmlns:A='DAV:'>
                            <A:prop>
                                <A:displayname/>
                            </A:prop>
                        </A:propfind>";
$c=curl_init($url);
curl_setopt($c, CURLOPT_HTTPHEADER, array("Depth: 1", "Content-Type: text/xml; charset='UTF-8'", "User-Agent: DAVKit/4.0.1 (730); CalendarStore/4.0.1 (973); iCal/4.0.1 (1374); Mac OS X/10.6.2 (10C540)"));
curl_setopt($c, CURLOPT_HEADER, 0);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($c, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($c, CURLOPT_USERPWD, $user.":".$pwd);
curl_setopt($c, CURLOPT_CUSTOMREQUEST, "PROPFIND");
curl_setopt($c, CURLOPT_POSTFIELDS, $body);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$data=curl_exec($c);
curl_close($c);

But in response i've got 500 Error. Any idea?

Also I'm trying use this link https://caldav.calendar.yahoo.com, but it's too 500 Error

test
  • 11
  • 4

2 Answers2

0

It's pretty simple, if you look at the source code of that page, you've got allllll of these hidden input fields:

<input type="hidden" name="sessionId" id="sessionId" value="8nPh4sVBtxEZ">
<input type="hidden" name=".tries" value="1">
<input type="hidden" name=".src" value="yc">
<input type="hidden" name=".md5" value="">
<input type="hidden" name=".hash" value="">
<input type="hidden" name=".js" value="">
<input type="hidden" name=".last" value="">
<input type="hidden" name="promo" value="">
<input type="hidden" name=".intl" value="us">
<input type="hidden" name=".lang" value="en-US">
<input type="hidden" name=".bypass" value="">
<input type="hidden" name=".partner" value="">
<input type="hidden" name=".u" value="336ng15a3fsqq">
<input type="hidden" name=".v" value="0">
<input type="hidden" name=".challenge" value="vrO9R3b_b7Qwm8roug2Ea0jjlIh022jt4w--">
<input type="hidden" name=".yplus" value="">
<input type="hidden" name=".emailCode" value="">
<input type="hidden" name="pkg" value="">
<input type="hidden" name="stepid" value="">
<input type="hidden" name=".ev" value="">
<input type="hidden" name="hasMsgr" value="0">
<input type="hidden" name=".chkP" value="Y">
<input type="hidden" name=".done" value="http://caldav.calendar.yahoo.com/">
<input type="hidden" name=".pd" value="yc_ver=0&c=&ivt=&sg=">
<input type="hidden" name=".ws" id=".ws" value="0">
<input type="hidden" name=".cp" id=".cp" value="0">     
<input type="hidden" name="nr" value="0">
<input type="hidden" name="pad" id="pad" value="6">
<input type="hidden" name="aad" id="aad" value="6">

And in one of those, you'll notice

<input type="hidden" name=".challenge" value="vrO9R3b_b7Qwm8roug2Ea0jjlIh022jt4w--">

That is what is causing the "500 Error." Why? Because you're writing a bot/scraper and the login form uses CSRF protection among other hack prevention techniques. Yahoo and all the big guys are actively writing code to stop you from doing exactly that.

If you're truly trying to interface with the CalDAV protocol that Yahoo provides, you'll probably need to be using a much different approach than cURL requests. There's probably some discussion of CalDAV PHP Client libraries out there

Community
  • 1
  • 1
sjagr
  • 15,983
  • 5
  • 40
  • 67
  • I'm trying to do this with DAViCal This is my sorce `require_once('davical/inc/caldav-client.php'); $cal = new CalDAVClient( "https://caldav.calendar.yahoo.com/", "*****@yahoo.com", "******" ); $options = $cal->DoOptionsRequest(); var_dump($options);` But on response I get 502 error. – test Oct 13 '14 at 09:05
0

This is my case

       $xml = "<A:propfind xmlns:A='DAV:'>
                            <A:prop>
                                <A:displayname/>
                            </A:prop>
                        </A:propfind>";

        $url = sprintf("https://caldav.calendar.yahoo.com/dav/%s/Calendar", $email);

        $headers = array(
            'Depth: 1',
            'Content-Type: text/xml; charset=utf-8',
            'Content-Length: '.strlen($xml),
            "User-Agent: DAVKit/4.0.1 (730); CalendarStore/4.0.1 (973); iCal/4.0.1 (1374); Mac OS X/10.6.2 (10C540)"
        );

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt($ch, CURLOPT_USERPWD, $email.":".$password);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PROPFIND');
        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);

        $response = curl_exec($ch);
        curl_close($ch);
test
  • 11
  • 4