本文整理汇总了PHP中OAuth::getAccessToken方法的典型用法代码示例。如果您正苦于以下问题:PHP OAuth::getAccessToken方法的具体用法?PHP OAuth::getAccessToken怎么用?PHP OAuth::getAccessToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OAuth
的用法示例。
在下文中一共展示了OAuth::getAccessToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCallback
public function actionCallback($oauth_token)
{
try {
$login_secret = $this->getSession('oauth')->login_secret;
if (!$oauth_token) {
echo "Error! There is no OAuth token!";
exit;
}
if (!$login_secret) {
echo "Error! There is no OAuth secret!";
exit;
}
$this->oauth->enableDebug();
$this->oauth->setToken($oauth_token, $login_secret);
$access_token_info = $this->oauth->getAccessToken(self::ACCESS_TOKEN_URL);
$this->getSession('oauth')->login_secret = false;
$this->getSession('oauth')->token = $access_token_info['oauth_token'];
$this->getSession('oauth')->secret = $access_token_info['oauth_token_secret'];
$this->getUserDetailsAndLoginUser();
} catch (OAuthException $E) {
Debugger::log($E);
//zalogujeme for sichr
echo "OAuth login failed. Please, contact administrator.";
$this->terminate();
}
}
示例2: connect
protected function connect()
{
$this->oauth->setToken($this->token, $this->tokenSecret);
$accessToken = $this->oauth->getAccessToken(self::URL_ACCESS . (Request::hasQuery('oauth_verifier') ? '?oauth_verifier=' . Request::getQuery('oauth_verifier') : ''));
$this->state = self::STATE_CONNECTED;
$this->token = $accessToken['oauth_token'];
$this->tokenSecret = $accessToken['oauth_token_secret'];
Session::set('Twitter_Token', $this->token);
Session::set('Twitter_TokenSecret', $this->tokenSecret);
Session::set('Twitter_State', $this->state);
TwCensus::redirect('/');
}
示例3: getTokenCredentials
public static function getTokenCredentials()
{
$result = array();
try {
$access_token_url = \Fuel\Core\Config::get('evernote.evernote_server') . '/oauth';
$oauth_verifier = \Fuel\Core\Session::get('oauthVerifier');
$oauth = new \OAuth(\Fuel\Core\Config::get('evernote.consumer_key'), \Fuel\Core\Config::get('evernote.consumer_secret'));
$request_token = \Fuel\Core\Session::get('requestToken');
$request_token_secret = \Fuel\Core\Session::get('requestTokenSecret');
$oauth->setToken($request_token, $request_token_secret);
$access_token_info = $oauth->getAccessToken($access_token_url, null, $oauth_verifier);
if ($access_token_info) {
$result['status'] = 'success';
$result['access_token'] = $access_token_info['oauth_token'];
$result['access_token_secret'] = $access_token_info['oauth_token_secret'];
$result['shard_id'] = $access_token_info['edam_shard'];
$result['user_id'] = $access_token_info['edam_userId'];
} else {
$result['status'] = 'failure';
}
} catch (\OAuthException $e) {
$result['status'] = 'failure';
}
return $result;
}
示例4: shouquan
public function shouquan($code, $openid, $openkey, $redirect_uri)
{
OAuth::init($this->client_id, $this->client_secret);
Tencent::$debug = $this->debug;
$callback = $redirect_uri;
//回调url
if ($code) {
//已获得code
//获取授权token
$url = OAuth::getAccessToken($code, $callback);
$r = Http::request($url);
parse_str($r, $out);
//存储授权数据
if (@$out['access_token']) {
$_SESSION['t_access_token'] = $out['access_token'];
$_SESSION['t_refresh_token'] = $out['refresh_token'];
$_SESSION['t_expire_in'] = $out['expires_in'];
$_SESSION['t_code'] = $code;
$_SESSION['t_openid'] = $openid;
$_SESSION['t_openkey'] = $openkey;
//验证授权
$r = OAuth::checkOAuthValid();
if ($r) {
//echo('<h3>授权成功!!!</h3><br>');
//print_r($r);exit;
//header('Location: ' . $callback);//刷新页面
return $r;
} else {
exit('<h3>授权失败,请重试</h3>');
}
} else {
exit($r);
}
}
}
示例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: getAccessToken
function getAccessToken($token, $token_secret, $verifier)
{
$oauth = new OAuth($this->site_id, $this->secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
$oauth->setToken($token, $token_secret);
$token_info = $oauth->getAccessToken(ENTRECARD_API_URL . "/access_token", null, $verifier);
return array($token_info['user_id'], $token_info['oauth_token'], $token_info['oauth_token_secret']);
}
示例7: getUser
/**
* Retrive Twitter auth data in Cookie set by Twitter JSSDK.
*
* @param CakeRequest $request Request object.
* @return mixed Either false or an object of user information of Twitter
*/
public function getUser(CakeRequest $request)
{
$api = Configure::read('SocialSignIn.API.Twitter');
// $request_token_url = 'http://api.twitter.com/oauth/request_token';
// $access_token_url = "http://twitter.com/oauth/access_token";
// $authorize_url="http://twitter.com/oauth/authorize";
$session_name = $this->settings['session'];
$s = SessionComponent::read($session_name);
// if already authenticated, user object is stored in the session
if (isset($s['User']) && is_object($s['User'])) {
return $s['User'];
}
if (isset($request->query['oauth_token']) && isset($s['secret'])) {
$oauth = new OAuth($this->settings['consumer_key'], $this->settings['consumer_secret'], OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
$oauth->setToken($request->query['oauth_token'], $s['secret']);
$access_token_info = $oauth->getAccessToken($api['access_token_url']);
if ($access_token_info['oauth_token']) {
$oauth->setToken($access_token_info['oauth_token'], $access_token_info['oauth_token_secret']);
$data = $oauth->fetch($api['fetch_url']);
$user = json_decode($oauth->getLastResponse());
return $user;
}
}
return false;
}
示例8: authorize
function authorize()
{
$oauth = new OAuth(Config::get('TWITTER_CONSUMER_KEY'), Config::get('TWITTER_CONSUMER_SECRET'), OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
$oauth->enableDebug();
try {
$request_token = $oauth->getRequestToken($this->request_token_url);
} catch (OAuthException $e) {
debug($oauth->debugInfo);
}
$url = $this->authorize_url . '?' . http_build_query(array('oauth_token' => $request_token['oauth_token'], 'callback_url'));
print 'Authorize: ' . $url . "\n";
system(sprintf('open %s', escapeshellarg($url)));
fwrite(STDOUT, "Enter the PIN: ");
$verifier = trim(fgets(STDIN));
//$oauth->setToken($token, $request_token['oauth_token_secret']);
//$access_token = $oauth->getAccessToken($this->access_token_url);
$oauth->setToken($request_token['oauth_token'], $request_token['oauth_token_secret']);
try {
$access_token = $oauth->getAccessToken($this->access_token_url, NULL, $verifier);
} catch (OAuthException $e) {
debug($oauth->debugInfo);
}
printf("'TWITTER_TOKEN' => '%s',\n'TWITTER_TOKEN_SECRET' => '%s',\n", $access_token['oauth_token'], $access_token['oauth_token_secret']);
exit;
}
示例9: authorize
public static function authorize($consumer_key, $consumer_secret, $request_token, $request_secret)
{
$oauth = new OAuth($consumer_key, $consumer_secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_FORM);
$oauth->setToken($request_token, $request_secret);
$access_token_info = $oauth->getAccessToken(GOOGLE_OAUTH_ACCESS_TOKEN_API);
return array("access_token" => $access_token_info["oauth_token"], "access_secret" => $access_token_info["oauth_token_secret"]);
}
示例10: setOAuth
function setOAuth()
{
// pecl_oauth
$oauth = new OAuth(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_FORM);
$oauth->enableDebug();
try {
if (isset($_GET['oauth_token'], $_SESSION['oauth_token_secret'])) {
$oauth->setToken($_GET['oauth_token'], $_SESSION['oauth_token_secret']);
$accessToken = $oauth->getAccessToken(TWITTER_ACCESS_URL);
$_SESSION['oauth_token'] = $accessToken['oauth_token'];
$_SESSION['oauth_token_secret'] = $accessToken['oauth_token_secret'];
$response = $oauth->getLastResponse();
parse_str($response, $get);
if (!isset($get['user_id'])) {
throw new Exception('Authentication failed.');
}
} else {
$requestToken = $oauth->getRequestToken(TWITTER_REQUEST_URL);
$_SESSION['oauth_token_secret'] = $requestToken['oauth_token_secret'];
header('Location: ' . TWITTER_AUTHORIZE_URL . '?oauth_token=' . $requestToken['oauth_token']);
die;
}
} catch (Exception $e) {
var_dump($oauth->debugInfo);
die($e->getMessage());
}
}
示例11: checkUser
public function checkUser($do)
{
// dump($_REQUEST);
// dump($do);
// exit;
OAuth::init(QQ_KEY, QQ_SECRET);
$callback = $this->getCallback('qq', $do);
if ($_REQUEST['code']) {
$code = $_REQUEST['code'];
$openid = $_REQUEST['openid'];
$openkey = $_REQUEST['openkey'];
//获取授权token
$url = OAuth::getAccessToken($code, $callback);
$r = Http::request($url);
parse_str($r, $out);
//存储授权数据
if ($out['access_token']) {
$_SESSION['t_access_token'] = $out['access_token'];
$_SESSION['t_refresh_token'] = $out['refresh_token'];
$_SESSION['t_expire_in'] = $out['expires_in'];
$_SESSION['t_code'] = $code;
$_SESSION['t_openid'] = $openid;
$_SESSION['t_openkey'] = $openkey;
$_SESSION['qq']['access_token'] = $out['access_token'];
$_SESSION['qq']['refresh_token'] = $out['refresh_token'];
$_SESSION['open_platform_type'] = 'qq';
//验证授权
$r = OAuth::checkOAuthValid();
if ($r) {
// header('Location: ' . $callback);//刷新页面
return true;
} else {
// exit('<h3>授权失败,请重试</h3>');
return false;
}
} else {
exit($r);
}
} else {
//获取授权code
if ($_GET['openid'] && $_GET['openkey']) {
//应用频道
$_SESSION['t_openid'] = $_GET['openid'];
$_SESSION['t_openkey'] = $_GET['openkey'];
//验证授权
$r = OAuth::checkOAuthValid();
if ($r) {
// header('Location: ' . $callback);//刷新页面
return true;
} else {
// exit('<h3>授权失败,请重试</h3>');
return false;
}
} else {
$url = OAuth::getAuthorizeURL($callback);
header('Location: ' . $url);
}
}
}
示例12: getAccessToken
public function getAccessToken($oauthToken, $oauthTokenSecret, $oauthVerifier)
{
$oauth = new \OAuth($this->consumerKey, $this->consumerSecret);
$oauth->setToken($oauthToken, $oauthTokenSecret);
$accessToken = $oauth->getAccessToken($this->getEndpoint('oauth'), null, $oauthVerifier);
$this->token = $accessToken['oauth_token'];
return $accessToken;
}
示例13: testError
public function testError()
{
$oauth = new OAuth('wx229aa24fa4a2xxxx', 'error_secret');
$oauth->getAccessToken('code', 'error_authorization_code');
$this->assertStringStartsWith('get access token failed: system error', $oauth->error());
$oauth = new OAuth('wx229aa24fa4a2xxxx', 'error_secret', 'error_access_token');
$oauth->api('sns/userinfo', array('openid' => 'error_openid'));
$this->assertStringStartsWith('request failed: invalid credential, access_token is invalid or not latest', $oauth->error());
}
示例14: GetAccessToken
/**
* @see OAuthHanlder::GetAccessToken()
*/
public function GetAccessToken($credentials, $verifier, $server = NULL)
{
$oauth = new OAuth($credentials['oauth_consumer_key'], $credentials['oauth_consumer_secret'], OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
$oauth->setRequestEngine(OAUTH_REQENGINE_CURL);
$oauth->setVersion('1.0a');
$oauth->setToken($credentials['oauth_token'], $credentials['oauth_token_secret']);
$endpoint = $this->GetAccessEndpoint($server);
$response = $oauth->getAccessToken($endpoint, NULL, $verifier);
$credentials['oauth_token'] = $response['oauth_token'];
$credentials['oauth_token_secret'] = $response['oauth_token_secret'];
return $credentials;
}
示例15: handleCallback
/**
* Handle callback by managing oauth token, saving oauth state and calling redirect URL
*
* @param Request $request
*/
public function handleCallback(Request $request)
{
try {
$this->api = new \OAuth($this->options['consumer_key'], $this->options['consumer_secret'], OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
$this->api->setToken($request->query->get('oauth_token'), $this->secret);
$accessToken = $this->api->getAccessToken($this->options['access_token_endpoint']);
$this->state = 2;
$this->token = $accessToken['oauth_token'];
$this->secret = $accessToken['oauth_token_secret'];
} catch (\Exception $e) {
$this->state = null;
}
$this->saveState();
header('HTTP/1.1 302 Found');
header('Location: ' . $this->redirectUrl);
}