Skip to content

Commit

Permalink
handle token carefully
Browse files Browse the repository at this point in the history
  • Loading branch information
clsung committed May 4, 2012
1 parent bb0fb88 commit 45011b2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion plurkOAuth.php
Expand Up @@ -35,6 +35,7 @@ function __construct($consumer_key, $consumer_secret,
} }


function _get_request_token() { function _get_request_token() {
unset($this->token);
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
if (substr($sapi_type, 0, 3) == 'cgi') { if (substr($sapi_type, 0, 3) == 'cgi') {
$content = $this->request(PLURK_REQUEST_TOKEN_PATH, null, array ( $content = $this->request(PLURK_REQUEST_TOKEN_PATH, null, array (
Expand Down Expand Up @@ -78,6 +79,7 @@ function _get_access_token() {
// XXX: print_r only for your first convenient, // XXX: print_r only for your first convenient,
// you should store in config.php // you should store in config.php
print_r($this->access_token); print_r($this->access_token);
unset($this->token);
$this->token = new Token( $this->token = new Token(
$this->access_token['oauth_token'], $this->access_token['oauth_token'],
$this->access_token['oauth_token_secret']); $this->access_token['oauth_token_secret']);
Expand Down Expand Up @@ -106,6 +108,7 @@ function authorize($access_token = NULL, $access_secret = NULL) {
$this->access_token['oauth_token_secret'] = $access_secret; $this->access_token['oauth_token_secret'] = $access_secret;
return true; return true;
} else { } else {
unset($this->access_token);
$this->_get_request_token(); $this->_get_request_token();
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
if (substr($sapi_type, 0, 3) == 'cgi') { if (substr($sapi_type, 0, 3) == 'cgi') {
Expand All @@ -123,7 +126,8 @@ function request($path, $params = null, $content = null) {
$params = array_merge ($params, $this->params); $params = array_merge ($params, $this->params);
else else
$params = $this->params; $params = $this->params;
if (isset ($this->access_token['oauth_token'])) if (isset ($this->access_token['oauth_token']) &&
isset ($this->access_token['oauth_token_secret']))
$this->token = new Token( $this->token = new Token(
$this->access_token['oauth_token'], $this->access_token['oauth_token'],
$this->access_token['oauth_token_secret']); $this->access_token['oauth_token_secret']);
Expand Down

0 comments on commit 45011b2

Please sign in to comment.