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

How to save data in google open spreadsheet in PHP without using Zend Gdata lib ? I cannot use Zend libs, as shown in Google tutorials, because the php server I am running the script on is php v. 5.0.4 . I tried to find a solution using cUrl, but I cannot omit the authentication problem when the doc is non-public. How should I do it? If someone tried to do this, please share the solution.

+4
source share
3 answers

I found a solution using curl and creating a google spreadsheet form. For the prepared table, you need to create a form without options: Require login to view this form and Automatically collect the responder username. Then check, using fe firebug, the post uri form and post data and use it for the 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); 

It may not be the perfect solution, but it works. :)

+5
source

Here's an object-oriented php class for sending data to a Google Docs spreadsheet - http://code.google.com/p/php-form-builder-class/source/browse/trunk/includes/class.spreadsheet.php? spec = svn384 & r = 384

cUrl is used instead of the Zend GData lib. Below you can find an example implementation. Remember to replace the test settings ("my_google_email", "my_google_password", etc.) with your specific information.

 $doc = new spreadsheet(); $doc->authenticate("my_google_email", "my_google_password"); $doc->setSpreadsheet("my_spreadsheet_title"); $doc->setWorksheet("my_worksheet_title"); $my_data = array("First Name" => "John", "Last Name" => "Doe"); $doc->add($my_data); 

The associative array keys passed to the add method must match the column headers of the tables that you use to collect data.

+2
source

You can access the GData APIs using regular HTTP requests; the library just makes it easier for you. Basically you just rewrite the bits of the library you want to use.

See the documentation.

0
source

All Articles