本文整理汇总了PHP中OAuthRequester类的典型用法代码示例。如果您正苦于以下问题:PHP OAuthRequester类的具体用法?PHP OAuthRequester怎么用?PHP OAuthRequester使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OAuthRequester类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: oauth3_obtain_feed
/**
* Returns the atom feed only requires oauth3/OAuthRequester.php
* TODO: will need to throw execptions for if user has no token, or if token no longer works... :/
*/
function oauth3_obtain_feed($user_id, $request_uri = 'https://mail.google.com/mail/feed/atom')
{
// Do we have a token for this user???
// if not return error print "no token found for" exit();
// if this is a curl call you can't use global user here
//$user_id= 5;
//$request_uri = 'https://mail.google.com/mail/feed/atom';
try {
$req = new OAuthRequester($request_uri, 'GET', $params = null);
$result = $req->doRequest($user_id);
//throws OAuthException exception on an error
// $result is an array of the form: array ('code'=>int, 'headers'=>array(), 'body'=>string)
$feed = $result['body'];
} catch (OAuthException $e) {
//print "Error: $e";
}
// TODO: how to return whatever error it says
// should return feed body Output while still testing
if (empty($feed) or !empty($e)) {
return "FALSE Error Message: {$e}";
// print "reasons for false or error info"; // or just log the error info
} else {
return $feed;
}
}
示例2: douban_callback
function douban_callback()
{
OAuthRequester::requestAccessToken(DOUBAN_KEY, $_SESSION['oauth_token'], 0, 'POST', $options = array('oauth_verifier' => $_SESSION['oauth_token']));
$req = new OAuthRequester('http://api.douban.com/people/' . urlencode('@me'), 'get');
$res = $req->doRequest();
$user_data = new SimpleXMLElement($res['body']);
$uid = array_pop(explode('/', $user_data->id));
$auth_type = 'douban';
$auth = R::findOne('oauth', "uid=? AND type=?", array($uid, $auth_type));
if (!$auth) {
$auth = R::dispense('oauth');
$auth->uid = $uid;
$auth->type = $auth_type;
$encrypt_key = rand(100000, 999999);
$auth->secret = $encrypt_key;
} else {
$encrypt_key = $auth->secret;
}
$cookie_str = sha1(implode('', array($uid, $auth_type, $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT'], $encrypt_key)));
$expire = time() + 3600 * 24 * 365;
setcookie('s', $cookie_str, $expire);
setcookie('auth_type', $auth_type, $expire);
setcookie('uid', $uid, $expire);
$auth->setMeta('buildcommand.unique', array(array('uid', 'type')));
$auth->setMeta('buildcommand.indexes', array('uid' => 'uid'));
R::store($auth);
}
示例3: requestRequestToken
/**
* Request a request token from the site belonging to consumer_key
*
* @param string consumer_key
* @param int usr_id
* @exception OAuthException when no key could be fetched
* @exception OAuthException when no server with consumer_key registered
* @return array (authorize_uri, token)
*/
static function requestRequestToken($consumer_key, $usr_id)
{
OAuthRequestLogger::start();
$store = OAuthStore::instance();
$r = $store->getServer($consumer_key);
$uri = $r['request_token_uri'];
$oauth = new OAuthRequester($uri, 'POST');
$oauth->sign($usr_id, $r);
$text = $oauth->curl_raw();
if (empty($text)) {
throw new OAuthException('No answer from the server "' . $uri . '" while requesting a request token');
}
$data = $oauth->curl_parse($text);
if ($data['code'] != 200) {
throw new OAuthException('Unexpected result from the server "' . $uri . '" (' . $data['code'] . ') while requesting a request token');
}
$token = array();
$params = explode('&', $data['body']);
foreach ($params as $p) {
@(list($name, $value) = explode('=', $p, 2));
$token[$name] = $oauth->urldecode($value);
}
if (!empty($token['oauth_token']) && !empty($token['oauth_token_secret'])) {
$store->addServerToken($consumer_key, 'request', $token['oauth_token'], $token['oauth_token_secret'], $usr_id);
} else {
throw new OAuthException('The server "' . $uri . '" did not return the oauth_token or the oauth_token_secret');
}
OAuthRequestLogger::flush();
// Now we can direct a browser to the authorize_uri
return array('authorize_uri' => $r['authorize_uri'], 'token' => $token['oauth_token']);
}
示例4: getIdentity
public function getIdentity($oauth_user_id)
{
// get twitter handle
#$request = new OAuthRequester('http://api.twitter.com/1/account/verify_credentials.xml', 'GET');
$request = new OAuthRequester('http://api.twitter.com/1/account/verify_credentials.json', 'GET');
$result = $request->doRequest($oauth_user_id);
if ($result['code'] == 200) {
$data = json_decode($result['body'], true);
if (is_null($data)) {
switch (json_last_error()) {
case JSON_ERROR_DEPTH:
error_log('JSON Error: Maximum stack depth exceeded');
break;
case JSON_ERROR_CTRL_CHAR:
error_log('JSON Error: Unexpected control character found');
break;
case JSON_ERROR_SYNTAX:
error_log('JSON Error: Syntax error, malformed JSON');
break;
case JSON_ERROR_NONE:
error_log('JSON Error: No errors');
break;
}
return null;
}
if (!is_null($data) && array_key_exists('id', $data) && array_key_exists('name', $data)) {
return $data;
}
}
return null;
}
示例5: getResponseAPI
function getResponseAPI($userIdZyncro, $sessionid, $serviceAPI)
{
// Init the OAuthStore
$options = array('consumer_key' => CONSUMER_KEY, 'consumer_secret' => CONSUMER_SECRET, 'server_uri' => OAUTH_HOST, 'request_token_uri' => REQUEST_TOKEN_URL, 'signature_methods' => array('HMAC-SHA1'), 'authorize_uri' => AUTHORIZE_URL, 'access_token_uri' => ACCESS_TOKEN_URL);
// Note: do not use "Session" storage in production. Prefer a database
// storage, such as MySQL.
OAuthStore::instance("Session", $options);
try {
// get a request token
$getRequestTokenParams = array();
$tokenResultParams = OAuthRequester::requestRequestToken(CONSUMER_KEY, 0, $getRequestTokenParams, 'GET');
// get an access token
$oauthToken = $tokenResultParams['token'];
$getAccessTokenParams = array('oauth_verifier' => $sessionid);
OAuthRequester::requestAccessToken(CONSUMER_KEY, $oauthToken, 0, 'POST', $getAccessTokenParams);
// make the request.
$urlRequest = OAUTH_HOST . $serviceAPI;
$request = new OAuthRequester($urlRequest, 'GET');
$result = $request->doRequest(0);
if ($result['code'] == 200) {
return $result['body'];
}
} catch (OAuthException2 $e) {
}
}
示例6: SignUrl
/**
* Given a URL return an OAuth signed URL. This will handle creating a timestamp and nonce
*
* @param string $url the unsigned url
* @param string $method request method GET, POST, PUT, DELETE
* @param string $key oauth key
* @param string $secret oauth secret
* @param array $params querystring or post parameters
* @param string $body the body contents of the request
* @param string $signature_method method used for signature (default = 'HMAC_SHA1')
*/
public static function SignUrl($url, $method, $key, $secret, $params = null, $body = null, $signature_method = 'HMAC_SHA1')
{
$options = array('consumer_key' => $key, 'consumer_secret' => $secret);
$params = $params ? $params : array();
OAuthStore::instance("2Leg", $options);
// Obtain a request object for the request we want to make
$request = new OAuthRequester($url, $method, $params, $body);
$sig = $request->sign($key, null, '');
$data = $request->signatureBaseString();
$url = substr(urldecode($data . '&oauth_signature=' . $request->calculateDataSignature($data, $secret, '', $signature_method)), strlen($method) + 1);
$url = VerySimpleStringUtil::ReplaceFirst('&', '?', $url);
return $url;
}
示例7: query
function query($query)
{
if (preg_match("/^SELECT|^SHOW|^DESCRIBE/i", $query)) {
$request = new OAuthRequester(URL . "?sql=" . rawurlencode($query), 'GET');
} else {
$request = new OAuthRequester(URL, 'POST', "sql=" . rawurlencode($query));
}
$result = $request->doRequest($this->user_id);
if ($result['code'] == 200) {
return $result['body'];
} else {
return null;
}
}
示例8: query
function query($query)
{
if (preg_match("/^SELECT|^SHOW|^DESCRIBE/i", $query)) {
$request = new OAuthRequester("https://www.googleapis.com/fusiontables/v1/query?sql=" . rawurlencode($query), 'GET');
} else {
$request = new OAuthRequester("https://www.googleapis.com/fusiontables/v1/query", 'POST', "sql=" . rawurlencode($query));
}
$result = $request->doRequest($this->user_id);
if ($result['code'] == 200) {
return $result['body'];
} else {
return null;
}
}
示例9: run_query
public function run_query($endpoint, $params, $method="GET")
{
if (!$this->apiKey)
throw new Semantics3_AuthenticationError('No API key provided.');
if (!$this->apiSecret)
throw new Semantics3_AuthenticationError('No API secret provided.');
$options = array( 'consumer_key' => $this->apiKey, 'consumer_secret' => $this->apiSecret );
OAuthStore::instance("2Leg", $options );
$url = $this->apiBase.$endpoint;
if ($method == "GET") {
$url = $url."?q=".urlencode(json_encode($params));
$params = null;
}
else {
$params = json_encode($params);
}
try
{
switch ($method) {
case "GET":
$request = new OAuthRequester($url, $method, $params);
break;
case "POST":
$request = new OAuthRequester($url, $method, '', $params);
break;
case "DELETE":
$request = new OAuthRequester($url, $method);
break;
default:
$request = new OAuthRequester($url, $method);
}
$result = $request->doRequest();
return $result['body'];
}
catch(OAuthException2 $e)
{
print "\n";
$error = $e->getMessage();
print $error."\n";
}
}
示例10: fGetTweets
function fGetTweets($user, $limit)
{
$options = array('consumer_key' => TWITTER_CONSUMER_KEY, 'consumer_secret' => TWITTER_CONSUMER_SECRET);
OAuthStore::instance("2Leg", $options);
try {
// Obtain a request object for the request we want to make
$request = new OAuthRequester(TWITTER_REQUEST_TOKEN_URL, "POST");
$result = $request->doRequest(0);
parse_str($result['body'], $params);
// now make the request.
$request = new OAuthRequester(TWITTER_PUBLIC_TIMELINE_API, 'GET', $params);
$result = $request->doRequest();
$response = $result['body'];
} catch (OAuthException2 $e) {
$response = "Exception" . $e->getMessage();
}
return $response;
}
示例11: getOAuthRequester
protected function getOAuthRequester($method, $url, $params)
{
switch ($method) {
case "GET":
$request = new OAuthRequester($url, $method, $params);
break;
case "POST":
$request = new OAuthRequester($url, $method, '', $params);
break;
case "DELETE":
$request = new OAuthRequester($url, $method);
break;
default:
$request = new OAuthRequester($url, $method);
}
$result = $request->doRequest();
return $result['body'];
}
示例12: readTimeline
function readTimeline($user, $count)
{
try {
// Obtain a request object for the request we want to make
$request = new OAuthRequester(TWITTER_REQUEST_TOKEN_URL, "POST");
$result = $request->doRequest(0);
parse_str($result['body'], $params);
// now make the request.
if ($user === false) {
$url = TWITTER_PUBLIC_TIMELINE_API;
} else {
$url = TWITTER_USER_TIMELINE_API . '?screen_name=' . $user . '&count=' . $count;
}
$request = new OAuthRequester($url, 'GET', $params);
$result = $request->doRequest();
$response = $result['body'];
} catch (OAuthException2 $e) {
$response = "Exception" . $e->getMessage();
}
return $response;
}
示例13: index
function index()
{
$options = array('consumer_key' => $this->key, 'consumer_secret' => $this->secret);
OAuthStore::instance("2Leg", $options);
$url = "http://api.twitter.com/1/statuses/home_timeline.format?include_entities=true";
// this is the URL of the request
$method = "GET";
// you can also use POST instead
$params = null;
try {
// Obtain a request object for the request we want to make
$request = new OAuthRequester($url, $method, $params);
// Sign the request, perform a curl request and return the results,
// throws OAuthException2 exception on an error
// $result is an array of the form: array ('code'=>int, 'headers'=>array(), 'body'=>string)
$result = $request->doRequest();
$response = $result['body'];
echo $response;
} catch (OAuthException2 $e) {
}
}
示例14: oauthAuthentication
/**
* send an api call to yotpo to authenticate and get an access token
* @return access token
*/
public function oauthAuthentication()
{
if ($this->app_key == null or $this->secret == null) {
Mage::log('Missing app key or secret');
return null;
}
$yotpo_options = array('consumer_key' => $this->app_key, 'consumer_secret' => $this->secret, 'client_id' => $this->app_key, 'client_secret' => $this->secret, 'grant_type' => 'client_credentials');
OAuthStore::instance("2Leg", $yotpo_options);
try {
$request = new OAuthRequester(self::YOTPO_OAUTH_TOKEN_URL, "POST", $yotpo_options);
if (!$request) {
Mage::log('Failed to get token access from yotpo api');
return null;
}
$result = $request->doRequest(0);
$tokenParams = json_decode($result['body'], true);
return $tokenParams['access_token'];
} catch (OAuthException2 $e) {
Mage::log('error: ' . $e);
return null;
}
}
示例15: run_query
public function run_query($endpoint, $query_arr)
{
if (!$this->apiKey) {
throw new Semantics3_AuthenticationError('No API key provided.');
}
if (!$this->apiSecret) {
throw new Semantics3_AuthenticationError('No API secret provided.');
}
$options = array('consumer_key' => $this->apiKey, 'consumer_secret' => $this->apiSecret);
OAuthStore::instance("2Leg", $options);
$url = "https://api.semantics3.com/v1/{$endpoint}?q=" . $query_arr;
$method = "GET";
$params = null;
try {
$request = new OAuthRequester($url, $method, $params);
$result = $request->doRequest();
return $result['body'];
} catch (OAuthException2 $e) {
print "\n";
$error = $e->getMessage();
print $error . "\n";
}
}