0

I want to read from and write to Google spreadsheet using google spreadsheet API, After long battle I was able to get access token and stored it in a session variable, but i don't understand how to exchange this token to get contents from spreadsheet and to update spreadsheet.

I was trying with below code to get a cell content. But nothing is being returned.

<?php
session_start();
$url =  'https://spreadsheets.google.com/feeds/cells/0AgxnPrGJ8****************RkMwSkZoQ2pXaFE/4/private/full/R2C2';

$headers = array(
                'Authorization' => 'Bearer '.$_SESSION['access_token'],
                'Gdata-version' => '3.0'                                                                        
            );

$postdata = http_build_query($headers);
$context =
        array("http"=>
        array(
            "method" => "GET",
            "content" => $postdata
             )
             ); 
$context = stream_context_create($context);
$ResultArray = file_get_contents($url, false, $context);
var_dump($ResultArray);
?>
Anees Hameed
  • 5,916
  • 1
  • 39
  • 43
  • Is the access_token valid, it expires after 1 hour. But looks cool, never it done in the raw, without the API – eddyparkinson Jan 01 '14 at 05:20
  • Hi Eddy, Yes, Access Token is valid. I refresh Access Token after it expires. – Anees Hameed Jan 01 '14 at 11:59
  • I am now able to read data from Google Spreadsheet and is now trying to write data back to the spreadsheet. To do this, I take a xml string, convert it to an xml using SimpleXMLElement, add this to post header. Post header will have now follwing components. **Method: 'Post', Content: $xml, Content-length: 'Length of the xml string', Gdata-version: 3.0, Content-type: 'application/atom+xml' and then the authorization token.** I tried but some error is shooting up. I will do some more experiments tonight. – Anees Hameed Jan 01 '14 at 12:13

1 Answers1

0

See Google Spreadsheets on http://framework.zend.com/manual/1.12/en/zend.gdata.html, if you wan`t have "long battles". Your can using components of Zend Framework separately (without install full ZF).

voodoo417
  • 11,861
  • 3
  • 36
  • 40
  • I got it worked with Zend framework. But I am trying to use pure php with out any framework. The problem that I face is on how compose the message with Authorization token and send it to server... – Anees Hameed Dec 31 '13 at 04:22
  • Zend framework was working well on local development server, but when I uploaded my app on to appstop.com, its not working. I am not able to write to google spreadsheet. :) – Anees Hameed Jan 05 '14 at 16:31