public function getAccessToken() { $consumer = new HTTP_OAuth_Consumer(constant('PUBLIC_KEY'), constant('PRIVATE_KEY'), $_SESSION['token'], $_SESSION['tokenSecret']); try { $consumer->getAccessToken(constant('ACCESS_TOKEN')); $_SESSION['accessToken'] = $consumer->getToken(); $_SESSION['accessTokenSecret'] = $consumer->getTokenSecret(); //header('Location: ' .'http://'.$_SERVER["PHP_SELF"]); header('Location: ../index.php'); } catch (Exception $e) { throw new \Exception("login::getAccessToken. Error Accessing"); } }
/** * Fetch an OAuth access token * * Requires an request_token to be present in self::$values * * @param string $consumerKey OAuth consumer application key * @param string $consumerSecret OAuth consumer secret key * @param string $url Access token url * @param array $params Paramters to include in the request * for the access token * @param string $method HTTP Method to use * * @return array Key => Value array of token and token secret * * @throws OpenID_Exception On no request_token in response message * @throws HTTP_OAuth_Exception On issue with getting the request token * * @see http://step2.googlecode.com/svn/spec/openid_oauth_extension/latest/openid_oauth_extension.html */ public function getAccessToken($consumerKey, $consumerSecret, $url, array $params = array(), $method = 'GET') { $requestToken = $this->get('request_token'); if ($requestToken === null) { throw new OpenID_Exception('No oauth request token in OpenID message'); } $consumer = new HTTP_OAuth_Consumer($consumerKey, $consumerSecret); $consumer->setToken($requestToken); // Token secret is blank per spec $consumer->setTokenSecret(''); // Blank verifier $consumer->getAccessToken($url, '', $params, $method); return array('oauth_token' => $consumer->getToken(), 'oauth_token_secret' => $consumer->getTokenSecret()); }
public function twitterAction() { // Get form $form = $this->view->form = new User_Form_Admin_Twitter(); $form->populate((array) Engine_Api::_()->getApi('settings', 'core')->core_twitter); // Get classes include_once 'Services/Twitter.php'; include_once 'HTTP/OAuth/Consumer.php'; if (!class_exists('Services_Twitter', false) || !class_exists('HTTP_OAuth_Consumer', false)) { return $form->addError('Unable to load twitter API classes'); } // Check data if (!$this->getRequest()->isPost()) { return; } if (!$form->isValid($this->getRequest()->getPost())) { return; } $values = $form->getValues(); if (empty($values['key']) || empty($values['secret'])) { $values['key'] = ''; $values['secret'] = ''; $values['enable'] = 'none'; } else { // Try to check credentials try { $twitter = new Services_Twitter(); $oauth = new HTTP_OAuth_Consumer($values['key'], $values['secret']); //$twitter->setOAuth($oauth); $oauth->getRequestToken('https://twitter.com/oauth/request_token'); $oauth->getAuthorizeUrl('http://twitter.com/oauth/authorize'); } catch (Exception $e) { return $form->addError($e->getMessage()); } } // Okay Engine_Api::_()->getApi('settings', 'core')->core_twitter = $form->getValues(); $form->addNotice('Your changes have been saved.'); $form->populate($values); }
function twipic($f, $a, $b, $m) { $twitpic_api = ""; $consumer_key = ""; $consumer_secret = ""; $access_token = $a; $access_token_secret = $b; $imagepath = $f; $message = $me; $consumer = new HTTP_OAuth_Consumer($consumer_key, $consumer_secret); $consumer->setToken($access_token); $consumer->setTokenSecret($access_token_secret); $http_request = new HTTP_Request2(); $http_request->setConfig('ssl_verify_peer', false); $consumer_request = new HTTP_OAuth_Consumer_Request(); $consumer_request->accept($http_request); $consumer->accept($consumer_request); $resp = $consumer->sendRequest('https://api.twitter.com/1.1/account/verify_credentials.json', array(), HTTP_Request2::METHOD_GET); $headers = $consumer->getLastRequest()->getHeaders(); $http_request->setHeader('X-Auth-Service-Provider', 'https://api.twitter.com/1.1/account/verify_credentials.json'); $http_request->setHeader('X-Verify-Credentials-Authorization', $headers['authorization']); $http_request->setUrl('http://api.twitpic.com/2/upload.json'); $http_request->setMethod(HTTP_Request2::METHOD_POST); $http_request->addPostParameter('key', $twitpic_api); $http_request->addPostParameter('message', $m); $http_request->addUpload('media', $imagepath); $resp = $http_request->send(); $body = $resp->getBody(); $body = json_decode($body, true); return $body; }
/** * Create a new instance of the adapter by wrapping an existing object. * @param HTTP_OAuth_Consumer $object * @return Imgur_HTTPAdapter_OAuth_HTTPOAuthConsumer **/ public static function createByWrapping($object) { $foo = new Imgur_HTTPAdapter_OAuth_HTTPOAuthConsumer(); $consumer_request = clone $object->getOAuthConsumerRequest(); // Oh, what a mess. $consumer_request->setSecrets($object->getSecrets()); $consumer_request->setParameters(array('oauth_consumer_key' => $object->getKey(), 'oauth_signature_method' => $object->getSignatureMethod(), 'oauth_token' => $object->getToken())); $foo->wrap($consumer_request); return $foo; }
/** * POST Request * * @param $url * @param $datas * @return string * @since version 2.1.0 */ public function post_request($url, $datas = array()) { $body = ''; try { $response = $this->oauth->sendRequest($url, $datas, HTTP_Request2::METHOD_POST); $body = $response->getBody(); } catch (Exception $e) { debug($e->getMessage()); } return $body; }
// Load dependencies include_once 'HTTP/OAuth/Consumer.php'; require_once 'HTTP/OAuth.php'; require_once 'HTTP/OAuth/Consumer/Request.php'; require_once 'HTTP/Request2.php'; // Set up HTTP request $httpRequest = new HTTP_Request2; $httpRequest->setHeader('Accept-Encoding', '.*'); $request = new HTTP_OAuth_Consumer_Request; $request->accept($httpRequest); // Set up OAuth consumer $consumer = new HTTP_OAuth_Consumer($consumer_key, $consumer_secret); $consumer->accept($request); // 1. Get request token $consumer->getRequestToken("http://".$domain."/oauth/request_token", "oob", array(), "GET"); // 2. Build authorize url and redirect the user $authorize_url = $consumer->getAuthorizeUrl("http://".$domain."/oauth/authorize"); echo("Please visit the following URL in your browser to authorize your application, then enter the 4 character security code when done:\n\n " . $authorize_url . "\n\nVerification code: "); // 3. Get an OAuth verifier (this step is only necessary when a callback url hasn't been specified) $handle = @fopen("php://stdin", "r"); $oauth_verifier = trim(fgets($handle)); fclose($handle); // 4. Exchange the request token for an access token
$getID = clean($_GET['id']); } //Get id of sensor if (isset($_GET['name'])) { $getName = clean($_GET['name']); } //Get name of sensor /* Request device history from Telldus Live --------------------------------------------------------------------------- */ if ($userTelldusConf['sync_from_telldus'] == 1) { require_once 'HTTP/OAuth/Consumer.php'; $getFrom = strtotime('- 7 days'); //One week back $getTo = time(); //Until now $consumer = new HTTP_OAuth_Consumer(constant('PUBLIC_KEY'), constant('PRIVATE_KEY'), constant('TOKEN'), constant('TOKEN_SECRET')); $params = array('id' => $getID, 'from' => $getFrom, 'to' => $getTo); $response = $consumer->sendRequest(constant('REQUEST_URI') . '/device/history', $params, 'GET'); $xmlString = $response->getBody(); $xmldata = new SimpleXMLElement($xmlString); echo "<div class='hidden-phone' style='float:right; margin-right:25px; margin-bottom:-50px; color:green; font-size:10px;'>{$lang['List synced']}</div>"; } /* List history --------------------------------------------------------------------------- */ echo "<h3 class='hidden-phone'>{$lang['Device History']}: (#{$getID}){$getName}</h3>"; if ($xmldata->history) { echo "<table class='table table-striped table-hover'>"; echo "<thead class='hidden-phone'>"; echo "<tr>"; echo "<th>{$lang['Time']}</th>"; echo "<th width='20%' style='text-align:left;'>{$lang['State']}</th>";
<?php header('Content-Type: application/javascript; charset=utf-8'); $_TARGET_URL = "https://api.twitter.com/1/statuses/home_timeline.json"; $consumer_key = 'hTuyvT5xm40IMbufsPDi2A'; $consumer_secret = '93XbloOTOxj3uMon8FxpadnhU04QtXVdfMxgjboWd0'; $access_token = '407672134-47bwS87O46HcwAw2q3TTo4uuDDmnSqGmVP0Iji6d'; $access_token_secret = 'A49YTyG2qJQkvaXtiT16uyOpYLKYlAtepUcp3PVHEw'; $time = time(); $oauth_nonce = md5($time . rand()); $callback = $_GET['callback']; //$time = '1321064592'; //$oauth_nonce = '2117191b637712cd6fe57b8b453c3893'; include_once 'HTTP/OAuth/Consumer.php'; $consumer = new HTTP_OAuth_Consumer($consumer_key, $consumer_secret); //認証用 $signature = HTTP_OAuth_Signature::factory($consumer->getSignatureMethod()); //signature作成用 //HTTPS接続の設定 $http_request = new HTTP_Request2(); $http_request->setConfig('ssl_verify_peer', false); $consumer_request = new HTTP_OAuth_Consumer_Request(); $consumer_request->accept($http_request); $consumer->accept($consumer_request); //Tokenの設定 $consumer->setToken($access_token); $consumer->setTokenSecret($access_token_secret); $page = '1'; $response = $consumer->sendRequest($_TARGET_URL, array('page' => $page, "include_entities" => true), "GET"); $json = json_decode($response->getBody(), true); echo $callback . "(" . json_encode($json) . ")";
/** * Makes an Flickr call * * The Flickr call is either made anoymously - if there are no access tokens - or OAuth signed. * * @param string $flickr_func The Flickr function to call * @param array $flickr_args Optional array containing the parameters for the function call * @param bool $force_anonymous Forces the call to be made anonymously (unsigned) * @return mixed|bool Will return false if there was an error, data specific to the function otherwise */ public function call($flickr_func, $flickr_args = array(), $force_anonymous = false) { $tokens = $this->getAccessTokens(); $full_args = array_merge((array) $flickr_args, array('method' => 'flickr.' . $flickr_func, 'api_key' => $this->key, 'format' => 'php_serial')); if (is_array($tokens) && isset($tokens['token_type']) && $tokens['token_type'] == 'access' && !$force_anonymous) { // Signed call (OAuth) $result = false; $consumer = new \HTTP_OAuth_Consumer($this->key, $this->secret, $tokens['token'], $tokens['token_secret']); try { $response = $consumer->sendRequest(static::FLICKR_REST_URL, $full_args); if ($response instanceof \HTTP_OAuth_Consumer_Response) { $result = @unserialize($response->getResponse()->getBody()); } } catch (\Exception $e) { } unset($consumer); // No longer needed return $result; } else { // Unsigned call $result = wp_remote_get(add_query_arg($full_args, static::FLICKR_REST_URL)); if (is_wp_error($result)) { return false; } else { return @unserialize(wp_remote_retrieve_body($result)); } } }
<?php require "lib/base.inc.php"; require "lib/auth.php"; /* Get parameters --------------------------------------------------------------------------- */ if (isset($_GET['id'])) { $getID = clean($_GET['id']); } if (isset($_GET['action'])) { $action = clean($_GET['action']); } /* Connect and send to telldus live --------------------------------------------------------------------------- */ require_once 'HTTP/OAuth/Consumer.php'; $consumer = new HTTP_OAuth_Consumer(constant('PUBLIC_KEY'), constant('PRIVATE_KEY'), constant('TOKEN'), constant('TOKEN_SECRET')); $params = array('id' => $getID, 'active' => $action); $response = $consumer->sendRequest(constant('REQUEST_URI') . '/scheduler/setJob', $params, 'GET');
if (isset($_GET['id'])) { $getID = clean($_GET['id']); } if (isset($_GET['action'])) { $action = clean($_GET['action']); } if (isset($_GET['state'])) { $state = clean($_GET['state']); } if (isset($_GET['btnID'])) { $btnID = clean($_GET['btnID']); } /* Connect and send to telldus live --------------------------------------------------------------------------- */ require_once 'HTTP/OAuth/Consumer.php'; $consumer = new HTTP_OAuth_Consumer(constant('PUBLIC_KEY'), constant('PRIVATE_KEY'), constant('TOKEN'), constant('TOKEN_SECRET')); if ($state == "on") { $params = array('id' => $getID); $response = $consumer->sendRequest(constant('REQUEST_URI') . '/device/turnOn', $params, 'GET'); //echo "<img style='height:11px' src='images/metro_black/check.png' alt='check' />"; } if ($state == "off") { $params = array('id' => $getID); $response = $consumer->sendRequest(constant('REQUEST_URI') . '/device/turnOff', $params, 'GET'); //echo "<img style='height:11px' src='images/metro_black/check.png' alt='check' />"; } /* echo '<pre>'; echo( htmlentities($response->getBody())); echo '</pre>';
<?php header("Content-type: text/event-stream; charset=utf-8"); header("Transfer-encoding: chunked"); $_TARGET_URL = "https://userstream.twitter.com/2/user.json"; $consumer_key = $consumer_secret = $access_token = $access_token_secret = $time = time(); $oauth_nonce = md5($time . rand()); include_once 'HTTP/OAuth/Consumer.php'; $consumer = new HTTP_OAuth_Consumer($consumer_key, $consumer_secret); //認証用 $signature = HTTP_OAuth_Signature::factory($consumer->getSignatureMethod()); //signature作成用 //HTTPS接続の設定 $http_request = new HTTP_Request2(); $http_request->setConfig('ssl_verify_peer', false); $consumer_request = new HTTP_OAuth_Consumer_Request(); $consumer_request->accept($http_request); $consumer->accept($consumer_request); //Tokenの設定 $consumer->setToken($access_token); $consumer->setTokenSecret($access_token_secret); //signature用の文字列設定 $param = array("oauth_consumer_key" => $consumer_key, "oauth_nonce" => $oauth_nonce, "oauth_signature_method" => $consumer->getSignatureMethod(), "oauth_timestamp" => $time, "oauth_token" => $access_token, "oauth_version" => "1.0"); //sigunature作成 $oauth_signature = urlencode($signature->build("GET", $_TARGET_URL, $param, $consumer_secret, $access_token_secret)); //echo 'Authorization: OAuth oauth_consumer_key="' . $consumer_key .'", oauth_nonce="'. $oauth_nonce .'", oauth_signature="' . $oauth_signature .'", oauth_signature_method="' . $consumer->getSignatureMethod() .'", oauth_timestamp="' . $time .'", oauth_token="' . $access_token .'", oauth_version="1.0"'; //HTTP通信ヘッダの作成 $options = array('http' => array('method' => "GET", 'header' => 'Authorization: OAuth oauth_consumer_key="' . $consumer_key . '", oauth_nonce="' . $oauth_nonce . '", oauth_signature="' . $oauth_signature . '", oauth_signature_method="' . $consumer->getSignatureMethod() . '", oauth_timestamp="' . $time . '", oauth_token="' . $access_token . '", oauth_version="1.0"', "Content-type: application/x-www-form-urlencoded\r\n")); //通信と出力 //JSONに変換可能だったもののみ、出力を行う。 $context = stream_context_create($options);
<?php /** * HTTP_OAuth * * Implementation of the OAuth specification * * PHP version 5.2.0+ * * LICENSE: This source file is subject to the New BSD license that is * available through the world-wide-web at the following URI: * http://www.opensource.org/licenses/bsd-license.php. If you did not receive * a copy of the New BSD License and are unable to obtain it through the web, * please send a note to license@php.net so we can mail you a copy immediately. * * @category HTTP * @package HTTP_OAuth * @author Jeff Hodsdon <*****@*****.**> * @copyright 2009 Jeff Hodsdon <*****@*****.**> * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @link http://pear.php.net/package/HTTP_OAuth_Provider * @link http://github.com/jeffhodsdon/HTTP_OAuth_Provider */ include_once 'HTTP/OAuth/Consumer.php'; $consumer = new HTTP_OAuth_Consumer($config->consumer_key, $config->consumer_secret, $config->token, $config->token_secret); try { echo $consumer->getAuthorizeUrl($config->authorize_url); } catch (Exception $e) { echo $e->getBody(); }
/* Don't run if last action was less than SET-secounds * This is to prevent sending data every time * 15 minutes => 900 sec * 30 minutes => 1800 sec * 60 minutes => 3600 sec */ if (900 < $timeSinceLastWarning) { $repeatDeviceState = true; } else { $repeatDeviceState = false; } if (empty($row['device'])) { $repeatDeviceState = false; } else { require_once 'HTTP/OAuth/Consumer.php'; $consumer = new HTTP_OAuth_Consumer(constant('PUBLIC_KEY'), constant('PRIVATE_KEY'), constant('TOKEN'), constant('TOKEN_SECRET')); if ($row['device_set_state'] == 1) { $deviceStateApiParameter = "turnOn"; } else { $deviceStateApiParameter = "turnOff"; } } /* Check for LESS THAN --------------------------------------------------------------------------- */ if ($row['direction'] == "less") { // CELSIUS if ($row['type'] == "celsius") { if ($tempData['temp_value'] < $row['warning_value']) { //echo "<b>WARNING: Temperature is less</b><br />{$lang['Notification mail low temperature']}<br /><br />"; // Send notification if ($repeatNotification) {
<?php require 'config.php'; session_start(); $network = $_GET['network']; $consumer = new HTTP_OAuth_Consumer($KEY, $SECRET); // $consumer->getRequestToken(REQUEST TOKEN URL, CALLBACK); $consumer->getRequestToken("http://" . $network . "/oauth/request_token", $CALLBACK); // Store tokens $_SESSION['token'] = $consumer->getToken(); $_SESSION['token_secret'] = $consumer->getTokenSecret(); $_SESSION['network'] = $network; $url = $consumer->getAuthorizeUrl('http://' . $network . '/oauth/authorize'); header("Location: {$url}"); ?>
/** * Sends a request using OAuth instead of basic auth * * @param string $uri The full URI of the endpoint * @param string $method GET or POST * @param array $params Array of additional parameter * @param array $files Array of files to upload * * @throws Services_Twitter_Exception on failure * @return HTTP_Request2_Response * @see prepareRequest() */ protected function sendOAuthRequest($uri, $method, $params, $files) { include_once 'HTTP/OAuth/Consumer/Request.php'; try { $request = clone $this->getRequest(); if ($method == 'POST') { foreach ($files as $key => $val) { $request->addUpload($key, $val); } } // Use the same instance of HTTP_Request2 $consumerRequest = new HTTP_OAuth_Consumer_Request(); $consumerRequest->accept($request); $this->oauth->accept($consumerRequest); $response = $this->oauth->sendRequest($uri, $params, $method); } catch (HTTP_Request2_Exception $exc) { throw new Services_Twitter_Exception($exc->getMessage(), $exc, $uri); } return $response; }
/* echo '<pre>'; echo( htmlentities($response->getBody())); echo '</pre>'; */ $xmlString = $response->getBody(); $xmldata = new SimpleXMLElement($xmlString); // Redirect header("Location: ?page=settings&view=sensors&msg=01"); exit; } /* activate sensor --------------------------------------------------------------------------- */ if ($action == "activateSensor") { require_once 'HTTP/OAuth/Consumer.php'; $consumer = new HTTP_OAuth_Consumer(constant('PUBLIC_KEY'), constant('PRIVATE_KEY'), constant('TOKEN'), constant('TOKEN_SECRET')); $params = array('id' => $getID, 'ignore' => '0'); $response = $consumer->sendRequest(constant('REQUEST_URI') . '/sensor/setIgnore', $params, 'GET'); /* echo '<pre>'; echo( htmlentities($response->getBody())); echo '</pre>'; */ $xmlString = $response->getBody(); $xmldata = new SimpleXMLElement($xmlString); // Redirect header("Location: ?page=settings&view=sensors&msg=02"); exit; } /* remove sensor --------------------------------------------------------------------------- */
require_once 'HTTP/OAuth/Store/Consumer/CacheLite.php'; $key = 'key'; $secret = 'secret'; $callback = 'http://openid.local/oauth.php'; $store = new HTTP_OAuth_Store_Consumer_CacheLite(); if (isset($_GET['start'])) { $consumer = new HTTP_OAuth_Consumer($key, $secret); $consumer->getRequestToken('http://twitter.com/oauth/request_token', $callback); $store->setRequestToken($consumer->getToken(), $consumer->getTokenSecret(), 'twitter', session_id()); $url = $consumer->getAuthorizeUrl('http://twitter.com/oauth/authorize'); header("Location: {$url}"); exit; } else { if (count($_GET)) { $tokens = $store->getRequestToken('twitter', session_id()); $consumer = new HTTP_OAuth_Consumer($key, $secret, $tokens['token'], $tokens['tokenSecret']); // Verifier $verifier = null; $qsArray = explode('?', $_SERVER['REQUEST_URI']); if (isset($qsArray[1])) { parse_str($qsArray[1], $parsed); if (isset($parsed['oauth_verifier'])) { $verifier = $parsed['oauth_verifier']; } } $consumer->getAccessToken('http://twitter.com/oauth/access_token', $verifier); $data = new HTTP_OAuth_Store_Data(); $data->consumerUserID = 'shupp'; $data->providerUserID = 'shupp'; $data->providerName = 'twitter'; $data->accessToken = $consumer->getToken();
* * PHP version 5.2.0+ * * LICENSE: This source file is subject to the New BSD license that is * available through the world-wide-web at the following URI: * http://www.opensource.org/licenses/bsd-license.php. If you did not receive * a copy of the New BSD License and are unable to obtain it through the web, * please send a note to license@php.net so we can mail you a copy immediately. * * @category HTTP * @package HTTP_OAuth * @author Jeff Hodsdon <*****@*****.**> * @copyright 2009 Jeff Hodsdon <*****@*****.**> * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @link http://pear.php.net/package/HTTP_OAuth_Provider * @link http://github.com/jeffhodsdon/HTTP_OAuth_Provider */ require_once 'examples-config.php'; include_once 'HTTP/OAuth/Consumer.php'; $consumer = new HTTP_OAuth_Consumer($config->consumer_key, $config->consumer_secret, $config->token, $config->token_secret); $consumer->accept($request); $args = array(); if ($config->method == 'POST' && !empty($_GET['args'])) { $args = $config->args; } try { $response = $consumer->sendRequest($config->protected_resource, $args, $config->method); echo "<pre>" . htmlentities($response->getBody()) . "</pre>"; } catch (HTTP_OAuth_Consumer_Exception_InvalidResponse $e) { echo $e->getBody(); }
* * LICENSE: This source file is subject to the New BSD license that is * available through the world-wide-web at the following URI: * http://www.opensource.org/licenses/bsd-license.php. If you did not receive * a copy of the New BSD License and are unable to obtain it through the web, * please send a note to license@php.net so we can mail you a copy immediately. * * @category HTTP * @package HTTP_OAuth * @author Jeff Hodsdon <*****@*****.**> * @copyright 2009 Jeff Hodsdon <*****@*****.**> * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @link http://pear.php.net/package/HTTP_OAuth_Provider * @link http://github.com/jeffhodsdon/HTTP_OAuth_Provider */ require_once 'examples-config.php'; include_once 'HTTP/OAuth/Consumer.php'; $consumer = new HTTP_OAuth_Consumer($config->consumer_key, $config->consumer_secret, $config->token, $config->token_secret); $consumer->accept($request); $args = array(); if ($config->method == 'POST' && !empty($_GET['args'])) { $args = $config->args; } try { $consumer->getAccessToken($config->access_token_url, $config->verifier, $args, $config->method); echo json_encode(array('token' => $consumer->getToken(), 'token_secret' => $consumer->getTokenSecret())); } catch (HTTP_OAuth_Consumer_Exception_InvalidResponse $e) { echo $e->getBody(); } catch (Exception $e) { echo $e->getMessage(); }
var rowId = $(this).attr("row-key"); var rowName = $(this).attr("row-name"); window.location="?page=sensors&sensor=yes&id="+rowId+"&name="+rowName; }); }); </script> <?php if (!$telldusKeysSetup) { echo "No keys for Telldus has been added... Keys can be added under <a href='getRequestToken.php'>your userprofile</a>."; exit; } /* Request sensors list from Telldus Live --------------------------------------------------------------------------- */ if ($userTelldusConf['sync_from_telldus'] == 1) { require_once 'HTTP/OAuth/Consumer.php'; $consumer = new HTTP_OAuth_Consumer(constant('PUBLIC_KEY'), constant('PRIVATE_KEY'), constant('TOKEN'), constant('TOKEN_SECRET')); $params = array(); $response = $consumer->sendRequest(constant('REQUEST_URI') . '/sensors/list', $params, 'GET'); /* echo '<pre>'; echo( htmlentities($response->getBody())); echo '</pre>'; */ $xmlString = $response->getBody(); $xmldata = new SimpleXMLElement($xmlString); /* Store sensors in DB --------------------------------------------------------------------------- */ foreach ($xmldata->sensor as $sensorData) { $sensorID = trim($sensorData['id']); $name = trim($sensorData['name']); $lastUpdate = trim($sensorData['lastUpdated']);
<?php require_once 'common.php'; $consumer = new HTTP_OAuth_Consumer(constant('PUBLIC_KEY'), constant('PRIVATE_KEY')); $consumer->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);
<?php require 'config.php'; session_start(); $network = $_SESSION['network']; $consumer = new HTTP_OAuth_Consumer($KEY, $SECRET, $_SESSION['token'], $_SESSION['token_secret']); $consumer->getAccessToken("http://" . $network . "/oauth/access_token", $_GET['oauth_verifier']); add_token($consumer->getToken(), $consumer->getTokenSecret(), $_SESSION['network']); header("Location: http://" . $network . "/oauth_clients/show?token=" . $consumer->getToken()); ?>
/** * @expectedException HTTP_OAuth_Exception */ public function testAcceptNotSupported() { $consumer = new HTTP_OAuth_Consumer('key', 'secret'); $consumer->accept(new stdClass()); }
<!-- <link rel="stylesheet" type="text/css" href="style.css" media="screen" /> <script src="jquery-1.7.1.min.js"></script> <script src="main.js"></script> --> </head> <body> <section> <h1>俺のホーム画面を見よ!</h1> <p>iPhoneのホーム画面をアップして自慢したり、おすすめアプリを紹介したりするサイトです。</p> <?php session_start(); $consumerKey = '4TtaSWDBXEIael6yEkwt2A'; $consumerSecret = '9W4dZUftwpAYGjwpAwO39i6jpeFQOLQNdqBD1cKEN0'; include 'HTTP/OAuth/Consumer.php'; $consumer = new HTTP_OAuth_Consumer($consumerKey, $consumerSecret); $callback = 'http://www.kenmaz.net/homescreen/twitter_auth.php'; $consumer->getRequestToken('http://twitter.com/oauth/request_token', $callback); $_SESSION['request_token'] = $consumer->getToken(); $_SESSION['request_token_secret'] = $consumer->getTokenSecret(); $auth_url = $consumer->getAuthorizeUrl('http://twitter.com/oauth/authorize'); ?> <!-- <a href="<?php echo $auth_url; ?> ">Twitterでログイン</a> --> <img src="upload/home.png" width="20%"><br> <?php for ($y = 0; $y < 4; $y++) {
$action = clean($_GET['action']); } /* Request event info from Telldus Live --------------------------------------------------------------------------- */ require_once 'HTTP/OAuth/Consumer.php'; $consumer = new HTTP_OAuth_Consumer(constant('PUBLIC_KEY'), constant('PRIVATE_KEY'), constant('TOKEN'), constant('TOKEN_SECRET')); $params = array('id' => $getID); $response = $consumer->sendRequest(constant('REQUEST_URI') . '/event/info', $params, 'GET'); $xmlString = $response->getBody(); $xmldata = new SimpleXMLElement($xmlString); if ($xmldata->trigger) { /* Store eventtrigger data --------------------------------------------------------------------------- */ foreach ($xmldata->trigger as $eventData) { $triggerID = trim($eventData['id']); $eventID = $getID; $deviceID = trim($eventData['deviceId']); $method = trim($eventData['method']); } foreach ($xmldata->description as $eventDesc) { $description = trim($eventDesc); } } /* Connect and send to telldus live --------------------------------------------------------------------------- */ $consumer2 = new HTTP_OAuth_Consumer(constant('PUBLIC_KEY'), constant('PRIVATE_KEY'), constant('TOKEN'), constant('TOKEN_SECRET')); $params2 = array('id' => $getID, 'description' => $description, 'active' => $action); $response2 = $consumer2->sendRequest(constant('REQUEST_URI') . '/event/setEvent', $params2, 'GET'); $consumer3 = new HTTP_OAuth_Consumer(constant('PUBLIC_KEY'), constant('PRIVATE_KEY'), constant('TOKEN'), constant('TOKEN_SECRET')); $params3 = array('id' => $triggerID, 'eventId' => $eventID, 'deviceId' => $deviceID, 'method' => $method); $response3 = $consumer3->sendRequest(constant('REQUEST_URI') . '/event/setDeviceTrigger', $params3, 'GET');
if (!strlen(CONSUMER_KEY)) { die("OAuth Consumer Key not set."); } if (!strlen(CONSUMER_SECRET)) { die("OAuth Consumer Secret not set."); } #unset($_SESSION['oauth_state']); if (!array_key_exists('oauth_state', $_SESSION)) { unset($_SESSION['token']); unset($_SESSION['token_secret']); $_SESSION['oauth_state'] = 0; } // You must have the PEAR directories in your include_path. They're present by default. include_once 'HTTP/OAuth.php'; include_once 'HTTP/OAuth/Consumer.php'; $oauth_pear = new HTTP_OAuth_Consumer(CONSUMER_KEY, CONSUMER_SECRET, isset($_SESSION['token']) ? $_SESSION['token'] : null, isset($_SESSION['token_secret']) ? $_SESSION['token_secret'] : null); // State = 0: The user has not attempted to request OAuth. if ($_SESSION['oauth_state'] == 0) { echo "Step 1: We've already registered with Imgur. Our consumer key is: ", CONSUMER_KEY, "<br>"; echo "Step 2: You have just made a request, and are thus reading this. Awesome.<br>"; echo "Step 3: Let's ask the Provider for a token:<br>"; try { // The inclusion of the callback URL in the token request causes the remote // service to know where to send the user back. It should be the same // callback URL that you registered with the servicve to get your key. $oauth_pear->getRequestToken(Imgur::$oauth1a_request_token_url, CALLBACK_URL); } catch (HTTP_OAuth_Consumer_Exception_InvalidResponse $e) { echo $e->getMessage(); exit; } // We'll stash away the *REQUEST* Token & Secret in the user's session.
<?php ob_start(); session_start(); require_once 'lib/base.inc.php'; require_once 'HTTP/OAuth/Consumer.php'; $consumer = new HTTP_OAuth_Consumer($userTelldusConf['public_key'], $userTelldusConf['private_key'], $_SESSION['token'], $_SESSION['tokenSecret']); try { $consumer->getAccessToken(constant('ACCESS_TOKEN')); $_SESSION['accessToken'] = $consumer->getToken(); $_SESSION['accessTokenSecret'] = $consumer->getTokenSecret(); header('Location:index.php'); } catch (Exception $e) { ?> <p>Authorization failed!</p> <p><a href="index.php">Go back</a></p> <?php }
// Content of multipart forms isn't signed according to the OAuth specs. // We handle this case by manually building the content of the multipart request // and then sending no params to the OAuth lib for signing. foreach ($params as $key => $val) { if ($key=='file') { $httpRequest->addUpload($key, $val); } else { $httpRequest->addPostParameter($key, $val); } } $params = array(); } // Set up OAuth consumer $request = new HTTP_OAuth_Consumer_Request; $request->accept($httpRequest); $consumer = new HTTP_OAuth_Consumer($visualplatform_config['key'], $visualplatform_config['secret'], $visualplatform_config['token'], $visualplatform_config['token_secret']); $consumer->accept($request); // Make request $response = $consumer->sendRequest("http://" . $visualplatform_config['domain'] . $endpoint, $params, "POST"); $data = $response->getBody(); if ( !$output_php_p ) { print($data); } else { print_r(json_decode($data)); } ?>