I get a 404 when doing a batch request for a provisioned user under a
hosted domain.
Here is the code:
function GConnect($url, $headers = null, $c_type = null, $body = null,
$timeout = 10, $redirects = 5) {
$fp = curl_init();
curl_setopt($fp, CURLOPT_ENCODING, '');
curl_setopt($fp, CURLOPT_URL, $url);
curl_setopt($fp, CURLOPT_HEADER, 1);
curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($fp, CURLOPT_TIMEOUT, $timeout);
curl_setopt($fp, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($fp, CURLOPT_REFERER, $url);
if (!is_array($headers)) $headers = array();
if (!is_array($load_headers)) $load_headers = array();
foreach ($headers as $key => $value) $load_headers[] = "$key:
$value";
curl_setopt($fp, CURLOPT_HTTPHEADER, $load_headers);
curl_setopt($fp, CURLOPT_FAILONERROR, 1);
if ($c_type == 'POST') {
curl_setopt($fp, CURLOPT_POST, true);
curl_setopt($fp, CURLOPT_POSTFIELDS, $body);
}
if ($c_type == 'PUT') {
$fdata = tmpfile();
fwrite($fdata, $body);
fseek($fdata, 0);
curl_setopt($fp, CURLOPT_PUT, true);
curl_setopt($fp, CURLOPT_INFILE, $fdata);
curl_setopt($fp, CURLOPT_INFILESIZE, strlen($body));
}
if ($c_type == 'DELETE') {
curl_setopt($fp, CURLOPT_CUSTOMREQUEST, "DELETE");
}
curl_setopt($fp, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($fp, CURLOPT_MAXREDIRS, $redirects);
$response = curl_exec($fp);
if (curl_errno($fp)) {
return 'cURL error ' . curl_errno($fp) . ': ' . curl_error($fp);
} else {
$info = curl_getinfo($fp);
if ($info['http_code'] == '302') {
$res = explode("\n", $response);
foreach ($res as $head) {
list($k, $v) = explode(": ", $head);
if ($k == 'Location') {
$response = GConnect($v, $headers, 'POST', $body);
}
}
}
curl_close($fp);
}
return $response;
}
// Check for authentication and login
$gcdomain = 'mydomain';
$gcpass = 'pass';
$gcuser = 'user';
$body = "&Email=".$gcuser."@".$gcdomain."&Passwd=".
$gcpass."&accountType=HOSTED&service=cl";
$url = "https://www.google.com/accounts/ClientLogin";
$feed = GConnect($url, $header_array, 'POST', $body);
list($headers,$body) = explode("\n\r", $feed);
$body_array = explode("\n", $body);
foreach ($body_array as $body) {
list($key, $val) = explode('=', $body);
if ($key == 'Auth') $client = $val;
}
$delete_batch = '<entry>
<batch:id>1</batch:id>
<batch:operation type="delete" />
<id>http://www.google.com/calendar/feeds/default/private/full/
pnovd1tj6e4oj4k9j856ts5j08</id>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://
schemas.google.com/g/2005#event'/>
<title type='text'>Event deleted via batch</title>
<link rel='alternate' type='text/html' href='http://www.google.com/
calendar/hosted/mydomain/event?
eid=cG5vdmQxdGo2ZTRvajRrOWo4NTZ0czVqMDggMTUwNjlAbXlyaWNoZGFkZHJlYW0uY29t'
title='alternate'/>
<link rel='self' type='application/atom+xml' href='http://
www.google.com/calendar/feeds/default/private/full/pnovd1tj6e4oj4k9j856ts5j08'/>
<link rel='edit' type='application/atom+xml' href='http://
www.google.com/calendar/feeds/default/private/full/pnovd1tj6e4oj4k9j856ts5j08/63346906976'/>
</entry>';
$body = "<feed xmlns='http://www.w3.org/2005/Atom'
xmlns:batch='http://schemas.google.com/gdata/batch' xmlns:gCal='http://
schemas.google.com/gCal/2005'><category scheme='http://
schemas.google.com/g/2005#kind' term='http://schemas.google.com/g/
2005#event' />$delete_batch</feed>";
$header_array = array('Authorization' => "GoogleLogin
auth={$client}", 'Content-Type' => 'application/atom+xml');
$url = "http://www.google.com/calendar/feeds/[EMAIL PROTECTED]/
private/full/batch";
$body = preg_replace("/\n/","",$body);
$feed = GConnect($url, $header_array, 'POST', $body);
cURL error 22: The requested URL returned error: 404
Let me know if anything sticks out that I'm doing wrong. I got the
links from a event request, so I know its valid.
--~--~---------~--~----~------------~-------~--~----~
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://groups.google.com/group/google-calendar-help-dataapi?hl=en
-~----------~----~----~----~------~----~------~--~---