本文整理汇总了PHP中OAuthRequester::doRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP OAuthRequester::doRequest方法的具体用法?PHP OAuthRequester::doRequest怎么用?PHP OAuthRequester::doRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OAuthRequester
的用法示例。
在下文中一共展示了OAuthRequester::doRequest方法的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: 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;
}
示例4: 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) {
}
}
示例5: request
/**
* Do request
*
* @param string $type Type of request
* @param string $url URL
* @param array $params (Optional) Parameters
* @access public
* @return mixed
*/
public function request($type, $url, $params = array())
{
ApiDebug::p('running request from ' . __CLASS__);
$oauth = $this->_getOAuthInstance();
$request = new \OAuthRequester(ApiUtils::getFullUrl($url, self::$_epoint), $type, $params);
$data = $request->doRequest(0, self::_getCurlOptions());
ApiDebug::p('got response from server', $data);
return $data['body'];
}
示例6: 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;
}
}
示例7: 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;
}
}
示例8: 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";
}
}
示例9: 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;
}
示例10: 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'];
}
示例11: 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) {
}
}
示例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: 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;
}
}
示例14: 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";
}
}
示例15: OAuthRequester
<?php
//session_destroy();
if (!empty($_SESSION['SFDOCTOR_TOKEN'])) {
try {
echo '<pre>GET: ' . $uriProfile . '<br/>';
print_r('');
echo '</pre>';
$tokenResultParams = $_SESSION['SFDOCTOR_TOKEN'];
$request = new OAuthRequester($uriProfile, 'GET', $tokenResultParams);
$result = $request->doRequest(0);
if ($result['code'] == 200) {
echo '<pre>';
print_r(json_decode($result['body']));
echo '</pre>';
exit;
} else {
echo 'Error';
}
} catch (OAuthException2 $e) {
echo '<pre>';
print_r('Error. Maybe you must login with 65dotor account.');
echo '</pre>';
echo '<pre>';
print_r($e->getMessage());
echo '</pre>';
echo '<pre>';
print_r($e);
echo '</pre>';
exit;
}