Created
March 22, 2012 18:44
-
-
Save brunnogomes/2161583 to your computer and use it in GitHub Desktop.
Redu PHP Client with OAuth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// this script requires the instalation of the Oauth library | |
// http://br.php.net/manual/en/book.oauth.php | |
$api_url = 'http://www.redu.com.br/api'; | |
$authorize_url = 'http://www.redu.com.br/oauth/authorize'; | |
$request_token_url = 'http://www.redu.com.br/oauth/request_token'; | |
$access_token_url = 'http://www.redu.com.br/oauth/access_token'; | |
$consumer_key = 'PUT_YOUR_CONSUMER_KEY_HERE'; | |
$consumer_secret = 'PUT_YOUR_CONSUMER_SECRET_HERE'; | |
session_start(); | |
// In state=1 the next request should include an oauth_token. | |
// If it doesn't go back to 0 | |
if(!isset($_GET['oauth_token']) && $_SESSION['state']==1) { | |
$_SESSION['state'] = 0; | |
} | |
try { | |
$oauth = new OAuth($consumer_key, | |
$consumer_secret, | |
OAUTH_SIG_METHOD_HMACSHA1, | |
OAUTH_AUTH_TYPE_URI); | |
$oauth->enableDebug(); | |
if(!isset($_GET['oauth_token']) && !$_SESSION['state']) { | |
$request_token_info = $oauth->getRequestToken($request_token_url); | |
$_SESSION['secret'] = $request_token_info['oauth_token_secret']; | |
$_SESSION['state'] = 1; | |
header('Location: '.$authorize_url.'?oauth_token='.$request_token_info['oauth_token']); | |
exit; | |
} else if($_SESSION['state']==1) { | |
$oauth->setToken($_GET['oauth_token'],$_SESSION['secret']); | |
$access_token_info = $oauth->getAccessToken($access_token_url); | |
$_SESSION['state'] = 2; | |
$_SESSION['token'] = $access_token_info['oauth_token']; | |
$_SESSION['secret'] = $access_token_info['oauth_token_secret']; | |
} | |
$oauth->setToken($_SESSION['token'],$_SESSION['secret']); | |
// fetching Redu Environments | |
$oauth->fetch("$api_url/environments.json"); | |
$json = json_decode($oauth->getLastResponse()); | |
var_dump($json); | |
} catch(OAuthException $E) { | |
var_dump($E); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment