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; }
/** * 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; }
public function testSendRequestUsingGET() { $url = 'http://example.com/protected_resource'; $method = 'GET'; $additional = array('foo' => 'bar', 'food' => 'pizza'); $con = new HTTP_OAuth_Consumer('key', 'secret', 'token', 'tokenSecret'); $con->accept(new HTTP_Request2(null, null, array('adapter' => 'Mock'))); $con->sendRequest($url, $additional, $method); $req = $con->getLastRequest(); $params = $req->getParameters(); $this->assertArrayHasKey('foo', $params); $this->assertEquals($params['foo'], 'bar'); $this->assertArrayHasKey('food', $params); $this->assertEquals($params['food'], 'pizza'); $this->assertTrue((bool) strstr($req->getUrl()->getQuery(), 'foo=bar&food=pizza')); $this->assertInstanceOf('HTTP_OAuth_Consumer_Response', $con->getLastResponse()); }
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>'; $xmlString = $response->getBody(); $xmldata = new SimpleXMLElement($xmlString); */
<?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) . ")";
//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>"; echo "</tr>"; echo "</thead>";
<?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');
// 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)); } ?>
//$params = array(); $params = array('listOnly' => 1); //$params = array('id'=> $getID); $response = $consumer->sendRequest(constant('REQUEST_URI') . '/events/list', $params, 'GET'); $xmlString = $response->getBody(); $xmldata = new SimpleXMLElement($xmlString); } /* Request schedules list from Telldus Live --------------------------------------------------------------------------- */ if ($userTelldusConf['sync_from_telldus'] == 1) { require_once 'HTTP/OAuth/Consumer.php'; $consumer2 = new HTTP_OAuth_Consumer(constant('PUBLIC_KEY'), constant('PRIVATE_KEY'), constant('TOKEN'), constant('TOKEN_SECRET')); //$params = array(); $params2 = array(); //$params = array('id'=> $getID); $response2 = $consumer2->sendRequest(constant('REQUEST_URI') . '/scheduler/joblist', $params2, 'GET'); $xmlString2 = $response2->getBody(); $xmldata2 = new SimpleXMLElement($xmlString2); echo "<div class='hidden-phone' style='float:right; margin-right:25px; margin-bottom:-50px; color:green; font-size:10px;'>{$lang['List synced']}</div>"; } /* List events --------------------------------------------------------------------------- */ echo "<h3 class='hidden-phone'>Telldus {$lang['Events']}</h3>"; if ($xmldata->event) { echo "<table class='table table-striped table-hover'>"; echo "<thead class='hidden-phone'>"; echo "<tr>"; echo "<th>{$lang['ID']}</th>"; echo "<th>{$lang['Name']}</th>"; echo "<th>{$lang['Active']}</th>"; echo "</tr>";
/** * 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( 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 --------------------------------------------------------------------------- */ if ($action == "removeSensor") { $query = "UPDATE " . $db_prefix . "sensors SET monitoring='" . 0 . "' WHERE sensor_id='" . $getID . "'";
* * 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(); }
/** * 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)); } } }
$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 // (He're we're reading extra data from the access token request to // determine the domain and user_id of the authenticated user. // Unfortunately this PHP OAuth library doesn't return the excess // data from the access token request, so we'll need to handle the // request manually.) $response = $consumer->sendRequest("http://".$domain."/oauth/access_token", array("oauth_verifier" => $oauth_verifier), "GET"); $data = $response->getDataFromBody(); if (empty($data['oauth_token']) || empty($data['oauth_token_secret'])) { throw new HTTP_OAuth_Consumer_Exception_InvalidResponse( 'Failed getting token and token secret from response', $response ); } print_r($data); $consumer->setToken($data['oauth_token']); $consumer->setTokenSecret($data['oauth_token_secret']);
} /* 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');
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']); $ignored = trim($sensorData['ignored']); $client = trim($sensorData['client']);
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) { $scheduleRun = true; // Get and replace variables in mail message $mailSubject = "{$config['pagetitle']}: {$lang['Warning']}: {$lang['Low']} {$lang['Temperature']}"; $mailMessage = "{$lang['Notification mail low temperature']}"; $mailMessage = str_replace("%%sensor%%", $row['name'], $mailMessage); $mailMessage = str_replace("%%value%%", $tempData['temp_value'], $mailMessage); } // Send state to device if ($repeatDeviceState) { $scheduleRun = true; $params = array('id' => $row['device']); $response = $consumer->sendRequest(constant('REQUEST_URI') . '/device/' . $deviceStateApiParameter, $params, 'GET'); } } } elseif ($row['type'] == "humidity") { if ($tempData['humidity_value'] < $row['warning_value']) { //echo "<b>WARNING: Humidity is less</b><br />"; if ($repeatNotification) { $scheduleRun = true; // Get and replace variables in mail message $mailSubject = "{$config['pagetitle']}: {$lang['Warning']}: {$lang['Low']} {$lang['Humidity']}"; $mailMessage = "{$lang['Notification mail low humidity']}"; $mailMessage = str_replace("%%sensor%%", $row['name'], $mailMessage); $mailMessage = str_replace("%%value%%", $tempData['humidity_value'], $mailMessage); } // Send state to device if ($repeatDeviceState) {