5 messages in com.googlegroups.google-base-data-api411 error. Length Requried
FromSent OnAttachments
Shawn13 Dec 2007 18:28 
Jeff S14 Dec 2007 14:19 
shallway14 Dec 2007 17:35 
M....@1210Solutions.com18 Dec 2007 07:43 
shallway18 Dec 2007 17:02 
Subject:411 error. Length Requried
From:Shawn (shal@gmail.com)
Date:12/13/2007 06:28:54 PM
List:com.googlegroups.google-base-data-api

Will you help me please! Here's what's confusing me these days. Environment: I have Apache2.2/PHP5.2.3 with cUrl PHP integreted. The curl function was tested out thru some testing page. 1.I downloaded this sample script from here: http://code.google.com/apis/base/samples/php/demo.php.txt. And it worked fine. 2.Since the sample script dealt with items of Recipe type and what I needed was to work with items of Product type. I decided

to write a new one to do the job. 3.In my script, I made up a test item in xml form named $test_item and it looks like the following:

$test_item = '<?xml version="1.0"?>'."\n"; $test_item .= '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:g="http://base.google.com/ns/1.0">'; $test_item .= '<id>$id</id>'; $test_item .= '<title type="text">'.$title.'</title>'; $test_item .= '<link rel="alternate" type="text/html" href='. $link.' />'; $test_item .= '<content>'.$description.'</content>'; $test_item .= '<g:item_type>'.$item_type.'</g:item_type>'; $test_item .= '<g:author>'; $test_item .= '<g:name>'.$author_name.'</g:name>'; $test_item .= '<g:email>'.$author_email.'</g:email>'; $test_item .= '</g:author>'; $test_item .= '<g:image_link>'.$p_image.'</g:image_link>'; $test_item .= '<g:product_type>'.$p_type.'</g:product_type>'; $test_item .= '<g:price>'.$p_price.'</g:price>'; $test_item .= '</entry>';

4.The token function was ok. Then I thought it would be quit simple just to create a curl object and send the above data to

google base. Here is the code:

function insertItem($item, $sessionToken){ global $devkey; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/base/feeds/ items'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); //for debugging purpose curl_setopt($ch, CURLOPT_POSTFIELDS, $item); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: AuthSub token='.$sessionToken.'\'', 'X-Google-Key: key=$devkey', 'Content-Type: application/atom+xml', )); $result = curl_exec($ch); curl_close($ch); return $result; }

5.I passed $test_itme to insertItem and it looked like this: insertItem($test_item, $token). Then I got this : Length Required POST requests require a Content-length header. 6.I tried to see what was curl doing. So I add 2 line2 to the above function : $info = curl_getinfo($ch); var_dump($info); 7.I noticed the 'Content-Type' field was 'text/html;charset=utf-8' from the output.While it should be 'application/atom+xml'

just like the code setted. 8.No matter what I set it to, it remained 'text/html' in the output. So I thought there might be something wrong in my curl

version or something. But since the sample script run ok. Why cant mine? 9.I thought well maybe it's the item xml I created in my script had something wrong. So I copy and paste the recipe xml from

the sample script and replaced it with the one in my script. Error remained. 10. Well it's great! It must be the script itself. I didn't know where but it must be some tricks in there. Since the sample

script was ok. So I thought maybe I just replace the xml data in it with that in my script. And I did that. Error remained.