SOLVED:

This is the final working code:


      function putfeed($feed,DOMDocument $datos,$token="")
          {
          $terminado=false;
          $headers=array("If-Match: *",
                                "X-HTTP-Method-Override: PUT",
                                "Content-Type: application/atom+xml",
                                "Accept-Language: es-es,en",
                                "GData-Version: 2",
                                "Content-Transfer-Encoding: binary",
                                "Authorization: GoogleLogin auth=".$token);
        $cookie=false;
              $handler = curl_init();
          while(!$terminado)
              {
              $headers2=$headers;
              if($cookie)$headers2[]="Cookie:".$cookie;
              $cookie=false;
            curl_setopt($handler, CURLOPT_URL, trim($feed));
            curl_setopt($handler, CURLOPT_HTTPHEADER, $headers2);
            curl_setopt($handler, CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; 
U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1");  
               curl_setopt($handler, CURLOPT_HEADER, 1);
            curl_setopt($handler, CURLOPT_POST      ,1);
            curl_setopt($handler, CURLOPT_TIMEOUT,30);
            curl_setopt($handler, CURLOPT_RETURNTRANSFER, TRUE);
             curl_setopt($handler, CURLOPT_POSTFIELDS    
,trim($datos->saveXML()));
            $response = curl_exec ($handler); 
            switch( curl_getinfo($handler, CURLINFO_HTTP_CODE))
                  {
                  case 200://Ok
                      $han=( explode("\r\n\r\n",$response));
                      $response = $han[count($han)-1];
                      $terminado=true; 
                      break;
                  case 201://created
                      $han=( explode("\r\n\r\n",$response));
                      $response = $han[count($han)-1];
                      $terminado=true; 
                      break;
                  case 302://redirect
                      $han=( explode("\r\n\r\n",$response));
                      $han = explode("\n",$han[0]);
                      $h=array();
                      foreach($han as $ha)
                          {
                          $ha=explode(":",$ha,2);
                          $h[$ha[0]]=$ha[1];
                          }
                      $feed=$h["Location"];
                      $cookie=$h["Set-Cookie"];
                      $terminado=false; 
                      break;
                  default://unknow
                      throw new Exception(curl_getinfo($handler, 
CURLINFO_HTTP_CODE));
              }
              }
          curl_close($handler);  
        return $response;
        }

-- 
You received this message because you are subscribed to the Google
Groups "Google Calendar Data API" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://code.google.com/apis/calendar/community/forum.html

Reply via email to