本文整理汇总了PHP中OAuth::getLastResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP OAuth::getLastResponse方法的具体用法?PHP OAuth::getLastResponse怎么用?PHP OAuth::getLastResponse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OAuth
的用法示例。
在下文中一共展示了OAuth::getLastResponse方法的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: 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;
}
}
示例3: 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;
}
示例4: 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;
}
}
示例5: 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;
}
示例6: getResponse
/**
* @return Response
*/
protected function getResponse()
{
$responseInfo = $this->oAuthClient->getLastResponseInfo();
$response = Response::createFromRaw($responseInfo['headers_recv']);
$response->appendContent($this->oAuthClient->getLastResponse());
return $response;
}
示例7: getResponse
/**
* @return Response
*/
protected function getResponse()
{
$responseHeaders = $this->oAuthClient->getLastResponseHeaders();
$response = Response::createFromRaw($responseHeaders);
$response->appendContent($this->oAuthClient->getLastResponse());
return $response;
}
示例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: 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();
}
示例10: 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();
}
}
示例11: 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();
}
}
示例12: linkedin
public function linkedin()
{
$oauth = new OAuth("772ot2tfqntox5", "Y6kUKUlWcWc6yDkd");
$oauth->setToken("94616be2-c292-472d-9f45-dfad9b78f2ef", "cdf34568-ed5f-4a27-a15d-4c8bf276fb4d");
$params = array();
$headers = array();
$method = OAUTH_HTTP_METHOD_GET;
$url = "https://api.linkedin.com/v1/people/~:(id,first-name,last-name,industry,picture-url,location:(name))?format=json";
$oauth->fetch($url, $params, $method, $headers);
$result = json_decode($oauth->getLastResponse(), true);
$this->info['nombre'] = $result['firstName'];
$this->info['apellido'] = $result['lastName'];
$this->info['foto'] = $result['pictureUrl'];
$this->info['ubicacion'] = $result['location']['name'];
$this->info['industria'] = $result['industry'];
}
示例13: fetch_tarball_via_oauth
protected static function fetch_tarball_via_oauth($key, $secret, $uri)
{
try {
$oauth = new OAuth($key, $secret);
$oauth->fetch($uri);
WP_CLI::debug($oauth->getLastResponseHeaders());
$headers = http_parse_headers($oauth->getLastResponseHeaders());
$mime_type = self::parse_content_type_header($headers['Content-Type']);
$content_disposition = self::parse_content_disposition_header($headers['Content-Disposition']);
$filename = empty($content_disposition['filename']) ? $filename = tmpfile() : sys_get_temp_dir() . DIRECTORY_SEPARATOR . $content_disposition['filename'];
file_put_contents($filename, $oauth->getLastResponse());
return $filename;
} catch (OAuthException $e) {
WP_CLI::error_multi_line($e->getMessage(), true);
}
WP_CLI::error('Unknown error', true);
}
示例14: request
private function request($method = 'GET', $path, $parameters = array(), $headers = array())
{
$url = rtrim($this->host, '/') . '/' . ltrim($path, '/');
try {
$result = $this->adapter->fetch($url, $parameters, strtoupper($method), $headers);
} catch (\OAuthException $e) {
$response = new Response($this->adapter->getLastResponse());
$json = $response->json();
if (empty($json->success)) {
throw new \Desk\Exception\ApiCallFailureException('Desk.com request failed', $response);
} else {
throw $e;
}
}
$body = $this->adapter->getLastResponse();
return new Response($body);
}
示例15: fetchJson
/**
* fetches JSON request on F1, parses and returns response
* @param string $url
* @param string|array $data
* @param const $method
* @return void
*/
public function fetchJson($url, $data = null, $method = OAUTH_HTTP_METHOD_GET)
{
try {
$o = new OAuth($this->settings->key, $this->settings->secret, OAUTH_SIG_METHOD_HMACSHA1);
$o->setToken($this->accessToken->oauth_token, $this->accessToken->oauth_token_secret);
$headers = array('Content-Type' => 'application/json');
if ($o->fetch($url, $data, $method, $headers)) {
if ($this->settings->debug) {
return array('headers' => self::http_parse_headers($o->getLastResponseHeaders()), 'response' => json_decode($o->getLastResponse(), true));
}
return json_decode($o->getLastResponse(), true);
}
} catch (OAuthException $e) {
$this->error = array('method' => $method, 'url' => $url, 'response' => self::http_parse_headers($o->getLastResponseHeaders()));
return $this->error;
}
}