From 06f945f27840b53e57795dadbc38e76f7e11ab1c Mon Sep 17 00:00:00 2001
From: Horus3
Date: Mon, 24 Feb 2014 16:42:14 +0100
Subject: init
---
zend/demos/Zend/Gdata/3LeggedOAuth/index.php | 190 +++++++++++++++++++++++++++
1 file changed, 190 insertions(+)
create mode 100755 zend/demos/Zend/Gdata/3LeggedOAuth/index.php
(limited to 'zend/demos/Zend/Gdata/3LeggedOAuth/index.php')
diff --git a/zend/demos/Zend/Gdata/3LeggedOAuth/index.php b/zend/demos/Zend/Gdata/3LeggedOAuth/index.php
new file mode 100755
index 0000000..59aab08
--- /dev/null
+++ b/zend/demos/Zend/Gdata/3LeggedOAuth/index.php
@@ -0,0 +1,190 @@
+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 '