From 6fa59e9ca978efd34c2798cd97609d9f956f9bd5 Mon Sep 17 00:00:00 2001 From: Micke Prag Date: Mon, 9 Jan 2012 12:37:41 +0100 Subject: [PATCH] Add Telldus Live! authentication example --- examples/php/live/authentication/common.php | 19 ++++++++ .../live/authentication/getAccessToken.php | 21 +++++++++ .../live/authentication/getRequestToken.php | 13 +++++ examples/php/live/authentication/index.php | 47 +++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 examples/php/live/authentication/common.php create mode 100644 examples/php/live/authentication/getAccessToken.php create mode 100644 examples/php/live/authentication/getRequestToken.php create mode 100644 examples/php/live/authentication/index.php diff --git a/examples/php/live/authentication/common.php b/examples/php/live/authentication/common.php new file mode 100644 index 00000000..05873f77 --- /dev/null +++ b/examples/php/live/authentication/common.php @@ -0,0 +1,19 @@ +getAccessToken(constant('ACCESS_TOKEN')); + + $_SESSION['accessToken'] = $consumer->getToken(); + $_SESSION['accessTokenSecret'] = $consumer->getTokenSecret(); + + header('Location:index.php'); +} catch (Exception $e) { + ?> +

Authorization failed!

+

Go back

+ getRequestToken(constant('REQUEST_TOKEN'), constant('BASE_URL').'/getAccessToken.php'); + +$_SESSION['token'] = $consumer->getToken(); +$_SESSION['tokenSecret'] = $consumer->getTokenSecret(); + +$url = $consumer->getAuthorizeUrl(constant('AUTHORIZE_TOKEN')); +header('Location:'.$url); diff --git a/examples/php/live/authentication/index.php b/examples/php/live/authentication/index.php new file mode 100644 index 00000000..a0a78db9 --- /dev/null +++ b/examples/php/live/authentication/index.php @@ -0,0 +1,47 @@ +We have no access token, connect us +

We have access!

+

+ In your system, store these values to do requests for this user:
+ Token:
+ Secret: +

+

Clear the token and restart

+

List users devices

+ constant('TELLSTICK_TURNON') | constant('TELLSTICK_TURNOFF'), + ); + $response = $consumer->sendRequest(constant('REQUEST_URI').'/devices/list', $params, 'GET'); + echo '
';
+	echo( htmlentities($response->getBody()));
+}
+
+?>

List users clients

sendRequest(constant('REQUEST_URI').'/clients/list', $params, 'GET'); + echo '
';
+	echo( htmlentities($response->getBody()));
+}
+
+