Exemple #1
0
 /**
  * @return bool
  * @throws \Exception
  */
 protected function verify()
 {
     if (!isset($_REQUEST['oauth_token'])) {
         return false;
     }
     if (isset($_REQUEST['oauth_token']) && $_SESSION['oauth_token'] !== $_REQUEST['oauth_token']) {
         $_SESSION['oauth_status'] = 'oldtoken';
         throw new \Exception('Problem with Twitter tokens');
     }
     /* Create TwitteroAuth object with app key/secret and token key/secret from default phase */
     $access_token = array('oauth_token' => $_SESSION['oauth_token'], 'oauth_token_secret' => $_SESSION['oauth_token_secret']);
     $this->connect($access_token);
     /* Save the access tokens. Normally these would be saved in a database for future use. */
     $_SESSION['access_token'] = $this->provider->getAccessToken($_REQUEST['oauth_verifier']);
     /* Remove no longer needed request tokens */
     //unset($_SESSION['oauth_token']);
     //unset($_SESSION['oauth_token_secret']);
     return true;
 }
<?php

session_start();
require_once 'twitteroauth/twitteroauth.php';
require_once 'config.php';
if (isset($_REQUEST['oauth_token']) && $_SESSION['oauth_token'] !== $_REQUEST['oauth_token']) {
    $_SESSION['status'] = 'old token';
    header('Location: clearsessions.php');
}
$connection = new TwitterOauth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
$access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']);
$_SESSION['access_token'] = $access_token;
unset($_SESSION['oauth_token']);
unset($_SESSION['oauth_token_secret']);
if ($connection->http_code == 200) {
    $_SESSION['status'] = 'verified';
    header('Location: index2.php');
} else {
    header('Location: clearsessions.php');
}