本文整理汇总了PHP中OAuth::fetch方法的典型用法代码示例。如果您正苦于以下问题:PHP OAuth::fetch方法的具体用法?PHP OAuth::fetch怎么用?PHP OAuth::fetch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OAuth
的用法示例。
在下文中一共展示了OAuth::fetch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUserDetailsAndLoginUser
protected function getUserDetailsAndLoginUser()
{
$this->oauth->setToken($this->getSession('oauth')->token, $this->getSession('oauth')->secret);
//fetch user datail XML
$this->oauth->fetch(self::API_URL . "user/details");
$user_details = $this->oauth->getLastResponse();
$xml = simplexml_load_string($user_details);
$user = array('id' => $xml->user['id'], 'username' => $xml->user['display_name'], 'account_created' => $xml->user['account_created'], 'img' => $xml->user->img['href'], 'changesets' => $xml->user->changesets['count'], 'traces' => $xml->user->traces['count'], 'description' => $xml->user->description, 'home_lat' => $xml->user->home['lat'], 'home_lon' => $xml->user->home['lon'], 'last_login' => date("Y-m-d H:i:s"));
// convert xml-nodes to strings
foreach ($user as &$val) {
$val = strval($val);
}
// update db
$row = dibi::fetch('SELECT * FROM users WHERE id = %i', $user['id']);
if ($row) {
//better dont change usernames, we use it as primary key
unset($user['username']);
dibi::query('UPDATE users SET ', $user, ' WHERE id = %i', $user['id']);
} else {
$user['first_login'] = new DateTime();
dibi::query('INSERT INTO users ', $user);
}
// load complete row from db
$dbuser = dibi::fetch('SELECT * FROM users WHERE id = %i', $user['id']);
if ($dbuser['webpages'] != 'admin' and $dbuser['webpages'] != 'all') {
$dbuser['webpages'] = '14' . ($dbuser['webpages'] ? ',' : '') . $dbuser['webpages'];
}
$this->user->login(new Identity($dbuser['username'], array($dbuser['webpages'] == 'admin' ? 'admin' : 'user'), $dbuser));
// remove all tokens - TODO if tokens to be used, save them in DB
$this->redirectUrl('//' . $_SERVER['HTTP_HOST'] . $this->getSession('oauth')->back_url);
}
示例2: sendPOST
/**
* Send a POST request to the specified URL with the specified payload.
* @param string $url
* @param string $data
* @return string Remote data
**/
public function sendPOST($url, $data = array())
{
$data['_fake_status'] = '200';
// Send the actual request.
try {
$this->instance->fetch($url, $data, OAUTH_HTTP_METHOD_POST, array('User-Agent' => sprintf(Imgur::$user_agent, Imgur::$key)));
} catch (OAuthException $e) {
throw new Imgur_Exception("Could not successfully do a sendPOST: " . $e->getMessage(), null, $e);
}
return $this->instance->getLastResponse();
}
示例3: twitter_post
function twitter_post($text, $short_url)
{
global $globals;
if (!class_exists("OAuth")) {
syslog(LOG_NOTICE, "Meneame: pecl/oauth is not installed");
return;
}
if (!$globals['twitter_consumer_key'] || !$globals['twitter_consumer_secret'] || !$globals['twitter_token'] || !$globals['twitter_token_secret']) {
syslog(LOG_NOTICE, "Meneame: consumer_key, consumer_secret, token, or token_secret not defined");
return;
}
$maxlen = 140 - 24;
//strlen($short_url);
$msg = mb_substr(text_to_summary(html_entity_decode($text), $maxlen), 0, $maxlen) . ' ' . $short_url;
$req_url = 'https://api.twitter.com/oauth/request_token';
$acc_url = 'https://api.twitter.com/oauth/access_token';
$authurl = 'https://api.twitter.com/oauth/authorize';
$api_url = 'https://api.twitter.com/1.1/statuses/update.json';
$oauth = new OAuth($globals['twitter_consumer_key'], $globals['twitter_consumer_secret'], OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
$oauth->debug = 1;
$oauth->setToken($globals['twitter_token'], $globals['twitter_token_secret']);
$api_args = array("status" => $msg, "empty_param" => NULL);
/* No using geo yet
if (isset($entry['lat'])) {
$api_args['lat'] = $entry['lat'];
$api_args['long'] = $entry['long'];
}
*/
try {
$oauth->fetch($api_url, $api_args, OAUTH_HTTP_METHOD_POST, array("User-Agent" => "pecl/oauth"));
} catch (Exception $e) {
syslog(LOG_INFO, 'Menéame, Twitter caught exception: ' . $e->getMessage() . " in " . basename(__FILE__) . "\n");
}
}
示例4: call
/**
* Call Twitter API methods
*
* @param string $method
* @param array $accessToken
* @param OAuth $oauth
* @param array $params (include oauth_method = POST/GET if need to override)
* @return string
*/
public static function call($method, $accessToken = null, OAuth $oauth, $params = array())
{
$oauth->setToken($accessToken['oauth_token'], $accessToken['oauth_token_secret']);
$resource = sprintf('%s/%s.json', 'https://api.twitter.com/1.1', $method);
// POST or GET
$method = OAUTH_HTTP_METHOD_GET;
if (isset($params['oauth_method'])) {
if ('POST' == strtoupper($params['oauth_method'])) {
$method = OAUTH_HTTP_METHOD_POST;
}
} else {
// If resource contains update, retweet (not retweets), filter, destroy, new, create - then POST not GET
foreach (array('update', 'retweet/', 'filter', 'destroy', 'new', 'create') as $resourcePart) {
if (false !== strpos($resource, $resourcePart)) {
$method = OAUTH_HTTP_METHOD_POST;
break;
}
}
}
if ($method == OAUTH_HTTP_METHOD_GET) {
if (count($params)) {
$resource = sprintf('%s?%s', $resource, http_build_query($params));
}
$params = null;
}
// Get back bad response if don't specify method where needs to be POST
if ($oauth->fetch($resource, $params, $method)) {
return $oauth->getLastResponse();
} else {
return null;
}
}
示例5: REST_Request
public function REST_Request($callbackUrl, $url, $method, $data = array())
{
/**
* Example of simple product POST using Admin account via Magento REST API. OAuth authorization is used
*/
$callbackUrl = $callbackUrl;
$temporaryCredentialsRequestUrl = $this->conf['magento_host'] . "/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
$adminAuthorizationUrl = $this->conf['magento_host'] . '/admin/oauth_authorize';
$accessTokenRequestUrl = $this->conf['magento_host'] . '/oauth/token';
$apiUrl = $this->conf['magento_host'] . '/api/rest';
$consumerKey = $this->conf['magentosoap_consumerKey'];
$consumerSecret = $this->conf['magentosoap_consumerSecret'];
$AccessToken = $this->conf["magentosoap_AccessToken"];
$AccessSecret = $this->conf["magentosoap_AccessSecret"];
try {
//$_SESSION['state'] = 2;
$authType = 2 == 2 ? OAUTH_AUTH_TYPE_AUTHORIZATION : OAUTH_AUTH_TYPE_URI;
$oauthClient = new OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, $authType);
$oauthClient->enableDebug();
$oauthClient->disableSSLChecks();
$oauthClient->setToken($AccessToken, $AccessSecret);
$resourceUrl = $apiUrl . $url;
$oauthClient->fetch($resourceUrl, $data, strtoupper($method), array("Content-Type" => "application/json", "Accept" => "*/*"));
//$oauthClient->fetch($resourceUrl);
$ret = json_decode($oauthClient->getLastResponse());
$ret = array("error" => 0, "data" => $ret);
return $ret;
} catch (OAuthException $e) {
$ret = array("error" => 1, "message" => "Checking quantity failed");
return $ret;
}
}
示例6: call
function call($command)
{
session_start();
if (!isset($_GET['oauth_token']) && $_SESSION['state'] == 1) {
$_SESSION['state'] = 0;
}
try {
$oauth = new \OAuth($this->consumer_key, $this->consumer_secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
$oauth->enableDebug();
if (!isset($_GET['oauth_token']) && !$_SESSION['state']) {
$request_token_info = $oauth->getRequestToken($this->request_url);
$_SESSION['secret'] = $request_token_info['oauth_token_secret'];
$_SESSION['state'] = 1;
header('Location: ' . $this->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($this->access_token_url);
error_log("acc token info " . $access_token_info, 1, "dustinmoorman@gmail.com");
$_SESSION['state'] = 2;
$_SESSION['token'] = $access_token_info['oauth_token'];
$_SESSION['secret'] = $access_token_info['oauth_token_secret'];
}
}
$oauth->setToken($_SESSION['token'], $_SESSION['secret']);
$oauth->fetch("{$this->api_url}{$command}");
$json = json_decode($oauth->getLastResponse());
} catch (\OAuthException $E) {
return $E->lastResponse;
}
return $json;
}
示例7: getTwitterFriendIds
function getTwitterFriendIds($user)
{
$cacheExpire = 24 * 60 * 60;
$POD = $user->POD;
$key = $POD->libOptions('twitter_api');
$secret = $POD->libOptions('twitter_secret');
$friends = array();
if ($user->get('twitter_token')) {
if ($user->get('twitter_list') != '' && time() - $user->get('twitter_list_generated') < $cacheExpire) {
$twoots = json_decode($user->get('twitter_list'));
foreach ($twoots as $f) {
$friends[] = $f;
}
} else {
try {
$oauth = new OAuth($key, $secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
$oauth->enableDebug();
// This will generate debug output in your error_log
$oauth->setToken($user->get('twitter_token'), $user->get('twitter_secret'));
$oauth->fetch('https://twitter.com/friends/ids.json?cursor=-1&user_id=' . $user->get('twitter_id'));
$json = json_decode($oauth->getLastResponse());
} catch (Exception $e) {
}
// contains the first 5000 twitter friends
foreach ($json->ids as $id) {
$friends[] = $id;
}
$user->addMeta('twitter_list', json_encode($friends));
$user->addMeta('twitter_list_generated', time());
}
}
return $friends;
}
示例8: getUserInfo
function getUserInfo($token, $secret)
{
$oauth = new OAuth(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
$oauth->setToken($token, $secret);
$oauth->fetch('http://twitter.com/account/verify_credentials.json');
$buf = $oauth->getLastResponse();
return json_decode($buf, true);
}
示例9: oauth_upload
function oauth_upload($comment, $data)
{
global $messages, $error;
if (!isset($_SESSION['osm_token']) || !isset($_SESSION['osm_secret'])) {
$error = _('OAuth token was lost, please relogin.');
oauth_logout();
return false;
}
try {
$stage = 'login';
$oauth = new OAuth(CLIENT_ID, CLIENT_SECRET, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
$oauth->setToken($_SESSION['osm_token'], $_SESSION['osm_secret']);
$change_data = create_changeset($data, $comment);
$xml_content = array('Content-Type' => 'application/xml');
$stage = 'create';
// note: this call works instead of returning 401 because of $xml_content
$oauth->fetch(OSM_API_URL . 'changeset/create', $change_data, OAUTH_HTTP_METHOD_PUT, $xml_content);
if (!preg_match('/\\d+/', $oauth->getLastResponse(), $m)) {
$error = _('Could not aquire changeset id for a new changeset.');
return false;
}
$changeset = $m[0];
$osc = create_osc($data, $changeset);
$stage = 'upload';
$oauth->fetch(OSM_API_URL . 'changeset/' . $changeset . '/upload', $osc, OAUTH_HTTP_METHOD_POST, $xml_content);
// todo: parse response and renumber created objects?
$stage = 'close';
$oauth->fetch(OSM_API_URL . 'changeset/' . $changeset . '/close', array(), OAUTH_HTTP_METHOD_PUT);
$chlink = '<a href="https://www.openstreetmap.org/changeset/' . $changeset . '" target="_blank">' . $changeset . '</a>';
// todo: replace %d with %s and $chlink, removing str_replace
$messages[] = '!' . str_replace($changeset, $chlink, sprintf(_('Changeset %d was uploaded successfully.'), $changeset));
return true;
} catch (OAuthException $E) {
if ($stage == 'upload' && $E->getCode() == 409) {
$error = sprintf(_('Conflict while uploading changeset %d: %s.'), $changeset, $oauth->getLastResponse());
// todo: process conflict
// http://wiki.openstreetmap.org/wiki/API_0.6#Error_codes_9
} else {
print_r($E);
$msg = $oauth->getLastResponse();
$error = sprintf(_('OAuth error %d at stage "%s": %s.'), $E->getCode(), $stage, $msg ? $msg : $E->getMessage());
}
}
return false;
}
示例10: GetReportsResponse
public function GetReportsResponse($requestParameters, $requestBody, $oauthRequestUri)
{
$this->context->IppConfiguration->Logger->CustomLogger->Log(TraceLevel::Info, "Called PrepareRequest method");
// This step is required since the configuration settings might have been changed.
$this->RequestCompressor = CoreHelper::GetCompressor($this->context, true);
$this->ResponseCompressor = CoreHelper::GetCompressor($this->context, false);
$this->RequestSerializer = CoreHelper::GetSerializer($this->context, true);
$this->ResponseSerializer = CoreHelper::GetSerializer($this->context, false);
// Determine dest URI
$requestUri = '';
if ($requestParameters->ApiName) {
// Example: "https://appcenter.intuit.com/api/v1/Account/AppMenu"
$requestUri = $this->context->baseserviceURL . $requestParameters->ApiName;
} else {
if ($oauthRequestUri) {
// Prepare the request Uri from base Uri and resource Uri.
$requestUri = $oauthRequestUri;
} else {
if ($requestParameters->ResourceUri) {
$requestUri = $this->context->baseserviceURL . $requestParameters->ResourceUri;
} else {
}
}
}
$oauth = new OAuth($this->context->requestValidator->ConsumerKey, $this->context->requestValidator->ConsumerSecret);
$oauth->setToken($this->context->requestValidator->AccessToken, $this->context->requestValidator->AccessTokenSecret);
$oauth->enableDebug();
$oauth->setAuthType(OAUTH_AUTH_TYPE_AUTHORIZATION);
$oauth->disableSSLChecks();
$httpHeaders = array();
if ('QBO' == $this->context->serviceType || 'QBD' == $this->context->serviceType) {
// IDS call
$httpHeaders = array('accept' => 'application/json');
// Log Request Body to a file
$this->RequestLogging->LogPlatformRequests($requestBody, $requestUri, $httpHeaders, TRUE);
if ($this->ResponseCompressor) {
$this->ResponseCompressor->PrepareDecompress($httpHeaders);
}
} else {
// IPP call
$httpHeaders = array('accept' => 'application/json');
}
try {
$OauthMethod = OAUTH_HTTP_METHOD_GET;
$oauth->fetch($requestUri, $requestBody, $OauthMethod, $httpHeaders);
} catch (OAuthException $e) {
//echo "ERROR:\n";
//print_r($e->getMessage()) . "\n";
list($response_code, $response_xml, $response_headers) = $this->GetOAuthResponseHeaders($oauth);
$this->RequestLogging->LogPlatformRequests($response_xml, $requestUri, $response_headers, FALSE);
return FALSE;
}
list($response_code, $response_xml, $response_headers) = $this->GetOAuthResponseHeaders($oauth);
// Log Request Body to a file
$this->RequestLogging->LogPlatformRequests($response_xml, $requestUri, $response_headers, FALSE);
return array($response_code, $response_xml);
}
示例11: call
/**
* Calls Netflix API methods
*
* @static
* @param $method
* @param null $accessToken
* @param OAuth $oauth
* @param array $params
* @return string
*/
public static function call($method, $accessToken = null, OAuth $oauth, $params = array())
{
$oauth->setToken($accessToken['oauth_token'], $accessToken['oauth_token_secret']);
$resource = sprintf('%s/%s?output=json', 'http://api.netflix.com', $method);
if (count($params)) {
$resource = sprintf('%s&%s', $resource, http_build_query($params));
}
if ($oauth->fetch($resource)) {
return $oauth->getLastResponse();
}
}
示例12: call
/**
* @param string $command
* @param string $method
* @param array $parameters
* @param array $content
* @return mixed $data
* @throws Exception
* @throws \TYPO3\Flow\Http\Exception
*/
public function call($command, $method = 'GET', array $parameters = array(), array $content = array())
{
$url = $this->apiUrl . $command;
$this->emitBeforeApiCall($url, $method);
try {
$this->oAuthClient->fetch($url, $parameters, $method);
} catch (\OAuthException $e) {
// we get a 404 Response here, so lets process it
}
$response = $this->getResponse();
$this->emitApiCall($url, $method, $response);
$statusCode = $response->getStatusCode();
if ($statusCode < 200 || $statusCode >= 400) {
throw new Exception('ApiRequest was not successful for command ' . $command . ' Response was: ' . $response->getStatus(), 1408987295);
}
$content = json_decode($response->getContent(), TRUE);
if ($content === NULL) {
throw new Exception('Response from ApiRequest is not a valid json', 1408987294);
}
return $content;
}
示例13: process
public function process($args)
{
$this->output = "";
$args = trim($args);
if (strlen($args) > 0) {
try {
$oauth = new OAuth($this->config["consumer_key"], $this->config["consumer_secret"], OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
$oauth->setToken($this->config["access_token"], $this->config["access_secret"]);
$hashtag = false;
if (preg_match("/^#/", $args)) {
$hashtag = true;
$oauth->fetch("https://api.twitter.com/1.1/search/tweets.json?q=" . urlencode($args) . "&count=3");
} else {
$args = str_replace("@", "", $args);
$oauth->fetch("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name={$args}&count=1");
}
$twitter_data = json_decode($oauth->getLastResponse());
if ($hashtag == false && count($twitter_data) > 0) {
$date = date('d/m/y H:i', strtotime($twitter_data[0]->created_at));
$this->output = "@{$args} : " . $twitter_data[0]->text . " -- {$date}";
} elseif ($hashtag && isset($twitter_data->statuses)) {
$twits = array();
foreach ($twitter_data->statuses as $twit) {
array_push($twits, $twit->text);
}
$this->output = "{$args}: " . join("\n", $twits);
} else {
if (is_array($twitter_data)) {
$this->output = "Ups! el usuario @{$args} no existe.";
} else {
$this->output = "El usuario @{$args} tiene sus twitts como privados.";
}
}
} catch (Exception $e) {
$this->output = "No fue posible obtener twitts de {$args}. Ha ocurrido un error.";
}
} else {
$this->output = "Ingresa un usuario.";
}
}
示例14: call
/**
* Calls Vimeo methods:
* @see http://vimeo.com/api/docs/methods
*
* @param String $method = Vimeo method to be called
* @param Array $accessToken
* @param OAuth $oauth
* @param Array $params - additional parameters required for Vimeo method
* @return String Json string
*/
public static function call($method, $accessToken = null, OAuth $oauth, $params = array())
{
if ($accessToken) {
$oauth->setToken($accessToken['oauth_token'], $accessToken['oauth_token_secret']);
}
$resource = sprintf('%s?method=%s&format=json', 'http://vimeo.com/api/rest/v2/', $method);
if (count($params)) {
$resource = sprintf('%s&%s', $resource, http_build_query($params));
}
if ($oauth->fetch($resource)) {
return $oauth->getLastResponse();
}
}
示例15: twitter_post
function twitter_post($auth, $text, $short_url, $image = false)
{
global $globals;
if (empty($auth['twitter_token']) || empty($auth['twitter_token_secret']) || empty($auth['twitter_consumer_key']) || empty($auth['twitter_consumer_secret'])) {
return false;
}
if (!class_exists("OAuth")) {
syslog(LOG_NOTICE, "Meneame: pecl/oauth is not installed");
return;
}
if (!$auth['twitter_consumer_key'] || !$auth['twitter_consumer_secret'] || !$auth['twitter_token'] || !$auth['twitter_token_secret']) {
syslog(LOG_NOTICE, "Meneame: consumer_key, consumer_secret, token, or token_secret not defined");
return;
}
$req_url = 'https://api.twitter.com/oauth/request_token';
$acc_url = 'https://api.twitter.com/oauth/access_token';
$authurl = 'https://api.twitter.com/oauth/authorize';
$api_url = 'https://api.twitter.com/1.1/statuses/update.json';
$api_media_url = 'https://api.twitter.com/1.1/statuses/update_with_media.json';
$api_args = array("empty_param" => NULL);
$maxlen = 140 - 24;
// minus the url length
if ($image) {
$maxlen -= 24;
echo "Adding image: {$image}\n";
$api_args['@media[]'] = '@' . $image;
$url = $api_media_url;
} else {
$url = $api_url;
}
$msg = mb_substr(text_to_summary(html_entity_decode($text), $maxlen), 0, $maxlen);
$msg_full = $msg . ' ' . $short_url;
$api_args["status"] = $msg_full;
$oauth = new OAuth($auth['twitter_consumer_key'], $auth['twitter_consumer_secret'], OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
$oauth->debug = 1;
$oauth->setRequestEngine(OAUTH_REQENGINE_CURL);
// For posting images
$oauth->setToken($auth['twitter_token'], $auth['twitter_token_secret']);
try {
$oauth->fetch($url, $api_args, OAUTH_HTTP_METHOD_POST, array("User-Agent" => "pecl/oauth"));
} catch (Exception $e) {
syslog(LOG_INFO, 'Menéame, Twitter caught exception: ' . $e->getMessage() . " in " . basename(__FILE__) . "\n");
echo "Twitter post failed: {$msg} " . mb_strlen($msg) . "\n";
return false;
}
// $response_info = $oauth->getLastResponseInfo();
// echo $oauth->getLastResponse() . "\n";
return true;
}