本文整理汇总了PHP中OAuth类的典型用法代码示例。如果您正苦于以下问题:PHP OAuth类的具体用法?PHP OAuth怎么用?PHP OAuth使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OAuth类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例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: 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: 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;
}
示例5: 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;
}
示例6: 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"]);
}
示例7: testHttpBuildQuery
public function testHttpBuildQuery()
{
$input = array('Name' => 'Gareth Wylie', 'Age' => 24, 'Formula' => 'a + b == 13%!');
$expect = 'Name=Gareth%20Wylie&Age=24&Formula=a%20%2B%20b%20%3D%3D%2013%25%21';
$oauth = new OAuth('foo', 'bar');
self::assertEquals($expect, $oauth->http_build_query($input));
}
示例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: 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;
}
示例10: 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);
}
示例11: ilost_get_fanauthorize
function ilost_get_fanauthorize()
{
$o = new OAuth(fan_akey, fan_skey);
$keys = $o->getRequestToken();
$aurl = $o->getAuthorizeURL($keys['oauth_token'], false, fan_callback);
$_SESSION['temp'] = $keys;
return $aurl;
}
示例12: __construct
public function __construct($consumer_key, $consumer_secret, $signature_method = OAUTH_SIG_METHOD_HMACSHA1, $auth_type = 0)
{
if (!class_exists('OAuth')) {
return ar_error::raiseError('OAuth PECL extension not installed', ar_exceptions::CONFIGURATION_ERROR);
}
$oauth = new OAuth($consumer_key, $consumer_secret, $signature_method, $auth_type);
$oauth->setRequestEngine(OAUTH_REQENGINE_STREAMS);
parent::__construct($oauth);
}
示例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: 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();
}
}
示例15: 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();
}