fetchRequestToken( implode(' ', $scopes), $APP_URL . '?action=access_token')); $consumer->authorizeRequestToken(); break; case 'access_token': $_SESSION['ACCESS_TOKEN'] = serialize($consumer->fetchAccessToken()); header('Location: ' . $APP_URL); break; default: if (isset($_SESSION['ACCESS_TOKEN'])) { $accessToken = unserialize($_SESSION['ACCESS_TOKEN']); $httpClient = $accessToken->getHttpClient( $consumer->getOauthOptions()); $docsService = new Zend_Gdata_Docs($httpClient, $APP_NAME); $spreadsheetsService = new Zend_Gdata_Spreadsheets($httpClient, $APP_NAME); // Retrieve user's list of Google Docs and spreadsheet list. $docsFeed = $docsService->getDocumentListFeed(); $spreadsheetFeed = $spreadsheetsService->getSpreadsheetFeed( 'http://spreadsheets.google.com/feeds/spreadsheets/private/full?max-results=100'); renderHTML($accessToken, array($docsFeed, $spreadsheetFeed)); } else { renderHTML(); } } /** * Returns a the base URL of the current running web app. * * @return string */ function getAppURL() { $pageURL = 'http'; if ($_SERVER['HTTPS'] == 'on') { $pageURL .= 's'; } $pageURL .= '://'; if ($_SERVER['SERVER_PORT'] != '80') { $pageURL .= $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['PHP_SELF']; } else { $pageURL .= $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF']; } return $pageURL; } /** * Removes session data and redirects the user to a URL. * * @param string $redirectUrl The URL to direct the user to after session data * is destroyed. * @return void */ function logout($redirectUrl) { session_destroy(); header('Location: ' . $redirectUrl); exit; } /** * Prints the token string and secret of the token passed in. * * @param Zend_OAuth_Token $token An access or request token object to print. * @return void */ function printToken($token) { echo 'Token:' . $token->getToken() . '
'; echo 'Token secret:' . $token->getTokenSecret() . '
'; } /** * Prints basic properties of a Google Data feed. * * @param Zend_Gdata_Feed $feed A feed object to print. * @return void */ function printFeed($feed) { echo '
    '; foreach ($feed->entries as $entry) { $alternateLink = ''; foreach ($entry->link as $link) { if ($link->getRel() == 'alternate') { $alternateLink = $link->getHref(); } } echo "
  1. $entry->title
  2. "; } echo '
'; } /** * Renders the page's HTML. * * @param Zend_OAuth_Token $token (optional) The user's current OAuth token. * @param array $feeds (optional) An array of Zend_Gdata_Feed to print * information for. * @return void */ function renderHTML($token=null, $feeds=null) { ?>
">Logout

First 100 documents from the Documents List Data API:

First 100 spreadsheets from the Spreadsheets Data API: