TwitterOAuth::getAccessToken PHP Method

getAccessToken() public method

Exchange request token and secret for an access token and secret, to sign API calls.
public getAccessToken ( $oauth_verifier )
    function getAccessToken($oauth_verifier)
    {
        $parameters = array();
        $parameters['oauth_verifier'] = $oauth_verifier;
        $request = $this->oAuthRequest($this->accessTokenURL(), 'GET', $parameters);
        $token = OAuthUtil::parse_parameters($request);
        $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
        return $token;
    }

Usage Example

Exemplo n.º 1
0
 public function callBack()
 {
     /* If the oauth_token is old redirect to the connect page. */
     //	if (isset($_REQUEST['oauth_token']) && $_SESSION['oauth_token'] !== $_REQUEST['oauth_token'])
     if (isset($_REQUEST['oauth_token']) && $this->session->userdata('oauth_token') !== $_REQUEST['oauth_token']) {
         //		$_SESSION['oauth_status'] = 'oldtoken';
         //		header('Location: ./clearsessions.php');
         echo "bad oauth_token";
         return false;
     }
     /* Create TwitteroAuth object with app key/secret and token key/secret from default phase */
     $connection = new TwitterOAuth(_TWITTER_CONSUMER_KEY_, _TWITTER_CONSUMER_SECRET_, $this->session->userdata('oauth_token'), $this->session->userdata('oauth_token_secret'));
     /* Request access tokens from twitter */
     $access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']);
     /* Save the access tokens. Normally these would be saved in a database for future use. */
     $_SESSION['access_token'] = $access_token;
     $this->db_update("users", $access_token, array("id" => $this->session->userdata('id')));
     //		/* Remove no longer needed request tokens */
     //		unset($_SESSION['oauth_token']);
     //		unset($_SESSION['oauth_token_secret']);
     /* If HTTP response is 200 continue otherwise send to connect page to retry */
     if (200 == $connection->http_code) {
         /* The user has been verified and the access tokens can be saved for future use */
         //			$_SESSION['status'] = 'verified';
         //			header('Location: ./index.php');
         echo "TWITTER OK";
     } else {
         /* Save HTTP status for error dialog on connnect page.*/
         //			header('Location: ./clearsessions.php');
         echo "ERROR";
     }
 }
All Usage Examples Of TwitterOAuth::getAccessToken