How to save data in unpublic google spreadsheet using PHP without Zend Gdata library?

gdata-api, google-sheets, php

Solution

I have found out solution using curl and by creating a form for the google's spreadsheet. For prepared spreadsheet you have to create a form, without options: Require sign-in to view this form and Automatically collect respondent's username. Then check, using f.e. firebug, the form post uri and post data and use it to following script:

#prepare post data
$fields = array('backupCache' => '',
            'entry.0.single'=>urlencode($data['name']),
            'entry.1.single'=>urlencode($data['surname']),
            'pageNumber'=>urlencode(0),   
            'submit'=>'Submit');
$fields_string = '';

foreach($fields as $key=>$value) {
  $fields_string .= $key.'='.$value.'&';
}

rtrim($fields_string,"& ");
$fields_string = substr($fields_string, 0, strlen($fields_string)-1);

$ch = curl_init();
#set curl_setopt for your preferences
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);    
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);    

curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);

#set proper form uri
curl_setopt($ch, CURLOPT_URL, $formUri);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);

$res = curl_exec($ch);
curl_close($ch);

May not be the most perfect solution but it works. :)

Problem

How can I save data in unpublic google spreadsheet in PHP without using Zend Gdata lib? I can't use Zend libs, as it's shown on google tutorials, because the php server on which I'm running the script is php v. 5.0.4. I tried to find a solution using cUrl, but I can't omit the problem with authentication when doc is unpublic. How can I do it? If anyone has attempted it, please share the solution.

Original source