Skip to content

Instantly share code, notes, and snippets.

@benjisimon
Created October 23, 2013 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benjisimon/7116355 to your computer and use it in GitHub Desktop.
Save benjisimon/7116355 to your computer and use it in GitHub Desktop.
A sample of the Simple Google Spredsheet API
<?php
/*
* A PHP file for testing the Simple Google Spreadsheet API
*/
date_default_timezone_set('UTC');
/* ------------------------------------------------------------------------
* Start Configuration
* ------------------------------------------------------------------------
*/
// Where's Zend's Loader.php
define('SGS_ZEND_LOADER', dirname(__FILE__) . "/../shared/lib/Zend/Loader.php");
// Define our connection info. Should use OAuth, but
// for the sake of simplicity, using an explicit username/password.
// May need to visit: https://accounts.google.com/DisplayUnlockCaptcha
// to allow your usename/password to work.
define('SGS_USERNAME', 'XXXXXXXXX@gmail.com');
define('SGS_PASSWORD', 'XXXXXXXXXXXXXXXXXXX');
// Lifted from the URL of Google Doc I want to work with
define('SGS_SHEET_ID', '0Ap3sMu55xO1GdEhtekhmY1B0Tk5obFp1RUhLMmpsNnc');
// Include the API
require_once('../lib/sgs.php');
/* ------------------------------------------------------------------------
* End Configuration
* ------------------------------------------------------------------------
*/
function add_last_accessed($data) {
$data['notes'] = "Last accessed " . date('r');
return $data;
}
sgs_walk("Address Book", 'add_last_accessed');
/*
* Now I can use sgs_list and sgs_walk as I like.
*/
?>
<h2>The Address Book</h2>
<ul>
<? foreach(sgs_list("Address Book") as $row) { ?>
<li>
<?= $row['name'] ?>
(<a href='mailto:<?= $row['e-mail'] ?>'><?=$row['e-mail']?></a>)
<a href='tel:<?= $row['phonenumber'] ?>'><?=$row['phonenumber']?></a> | <?= $row['notes'] ?>
</li>
<? } ?>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment