I try to add a worksheet with PHP curl commands.
Below is my code and the response.

$url = "https://spreadsheets.google.com";;
$urlPath = "/feeds/worksheets/[my spreadsheet key]/private/full/";
$postvars = "<entry xmlns=\"http://www.w3.org/2005/Atom\"; 
xmlns:gs=\"http://schemas.google.com/spreadsheets/2006\";><title>new_sheet</title><gs:rowCount>50</gs:rowCount><gs:colCount>10</gs:colCount></entry>";
$header = "POST ".$urlPath." HTTP/1.0\r\n";
$header.= "Content-type: application/atom+xml\r\n";
$header.= "Content-length: ".strlen($postvars)."\r\n";
$header.= "Authorization: GoogleLogin auth=".$auth."\r\n";
$header.= "X-GData-Key: key=[my development key]\r\n";
$header.= "If-Match: *\r\n";
$header.= "GData-Version: 3.0";

curl_setopt($session, CURLOPT_URL, $url.$urlPath); 
curl_setopt ($session, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt ($session, CURLOPT_HTTPHEADER, array($header));
curl_setopt ($session, CURLOPT_POSTFIELDS, $postvars);
curl_setopt($session, CURLOPT_HEADER, true);
curl_setopt ($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
if (curl_errno($session)) {
print "Error: ".curl_error($session);
} else {
echo $response;
}

HTTP/1.1 400 Bad Request Content-Type: text/html; charset=UTF-8 
x-chromium-appcache-fallback-override: disallow-fallback Date: Fri, 08 Jun 
2012 00:35:11 GMT Expires: Fri, 08 Jun 2012 00:35:11 GMT Cache-Control: 
private, max-age=0 X-Content-Type-Options: nosniff X-Frame-Options: 
SAMEORIGIN X-XSS-Protection: 1; mode=block Server: GSE Transfer-Encoding: 
chunked Content is not allowed in prolog. 

The same header and body can work with curl command in unix.
Any can help me? 
Thanks a lot.

Tony Huang

Reply via email to