url() public method

Make URLs for user browser navigation.
public url ( string $path, array $parameters ) : string
$path string
$parameters array
return string
 /**
  * Redirects the user to Twitter's API login page.
  *
  * @see https://dev.twitter.com/web/sign-in/implementing
  * @see https://twitteroauth.com/redirect.php
  */
 public function login()
 {
     $aRequestToken = $this->getRequestToken();
     if ($aRequestToken) {
         $sTwitterLoginUrl = $this->_oTwitterOAth->url('oauth/authorize', ['oauth_token' => $aRequestToken['oauth_token']]);
         URL::redirect($sTwitterLoginUrl);
     }
     return false;
 }
Beispiel #2
0
 public function getUrlLogin()
 {
     $connection = new TwitterOAuth($this->consumer_key, $this->consumer_secret);
     $request_token = $connection->oauth('oauth/request_token', ['oauth_callback' => 'http://api.uhealth.com.br/v1/twitterCallback']);
     $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
     return $connection->url('oauth/authorize', ['oauth_token' => $request_token['oauth_token']]);
 }
Beispiel #3
0
 public function getAuthorizationUrl(array $options = [])
 {
     $connection = new TwitterOAuth($this->clientId, $this->clientSecret);
     $request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => $this->redirectUri));
     $options["session"]->write('twitter.request_token', $request_token);
     $url = $connection->url('oauth/authenticate', array('oauth_token' => $request_token['oauth_token']));
     return $url;
 }
Beispiel #4
0
 public static function getBotAuthorizeURL($route = "/")
 {
     $connection = new TwitterOAuth(CONSUMER_KEY_BOT, CONSUMER_SECRET_BOT);
     $response = $connection->oauth("oauth/request_token", array("oauth_callback" => "http://" . $_SERVER['SERVER_NAME'] . $route));
     $_SESSION['oauth_token_bot'] = $response['oauth_token'];
     $_SESSION['oauth_token_secret_bot'] = $response['oauth_token_secret'];
     $url = $connection->url("oauth/authorize", array("oauth_token" => $response['oauth_token']));
     return $url;
 }
 function GenerateLoginLink()
 {
     $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
     $request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => OAUTH_CALLBACK));
     $_SESSION['oauth_token'] = $request_token['oauth_token'];
     $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
     $url = $connection->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token']));
     return $url;
 }
 public function authorize()
 {
     $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
     $request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => OAUTH_CALLBACK));
     setcookie('oauth_token', $request_token['oauth_token']);
     setcookie('oauth_token_secret', $request_token['oauth_token_secret']);
     $url = $connection->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token']));
     header("Location: {$url}");
 }
 public function getAuthUrl()
 {
     $connection = new TwitterOAuth(self::CONSUMER_KEY, self::CONSUMER_SECRET);
     $request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => self::OAUTH_CALLBACK));
     $_SESSION['oauth_token'] = $request_token['oauth_token'];
     $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
     $url = $connection->url('oauth/authenticate', array('oauth_token' => $request_token['oauth_token']));
     return $url;
 }
Beispiel #8
0
 /**
  * Returns twitter login start auth process
  * 
  * @param string $redirecturl URL where to redirect after login complete
  */
 public function getLoginStartUrl($redirecturl)
 {
     $connection = new TwitterOAuth($this->options['consumer_key'], $this->options['consumer_secret']);
     $request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => $redirecturl));
     $this->request_token = array();
     $this->request_token['oauth_token'] = $request_token['oauth_token'];
     $this->request_token['oauth_token_secret'] = $request_token['oauth_token_secret'];
     return $connection->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token']));
 }
 public function getAccessToken()
 {
     $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
     $request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => OAUTH_CALLBACK));
     Session::put('oauth_token', $request_token['oauth_token']);
     Session::put('oauth_token_secret', $request_token['oauth_token_secret']);
     $url = $connection->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token']));
     return $url;
 }
 public function twitter()
 {
     $connection = new TwitterOAuth(Config::get('twitter.appid'), Config::get('twitter.secret'));
     $request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => Config::get('twitter.callback')));
     $_SESSION['login_type'] = "twitter";
     $_SESSION['oauth_token'] = $request_token['oauth_token'];
     $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
     $url = $connection->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token']));
     return redirect($url);
 }
Beispiel #11
0
 public function action_signInWithTwitter()
 {
     $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
     $request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => OAUTH_CALLBACK));
     //echo var_dump($request_token);
     $_SESSION['oauth_token'] = $request_token['oauth_token'];
     $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
     $url = $connection->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token']));
     header("Location: " . $url);
     die;
 }
 /**
  * Generate Authorization URL
  *
  * Generate an authorization URL twitter.
  *
  * @return string
  * @throws Exception
  */
 public function authorizeURL()
 {
     $twitter = new TwitterOAuth($this->config->get('twitter', 'consumer'), $this->config->get('twitter', 'secret'));
     $twitter->setDecodeJsonAsArray(true);
     $requestToken = $twitter->oauth('oauth/request_token', array('oauth_callback' => Utility::buildFullLink($this->config, false, 'session/callback/twitter')));
     if ($requestToken['oauth_callback_confirmed'] != true) {
         throw new Exception("OAuth Callback was not confirmed.");
     }
     $this->session->setTMP('twitter_request_token', $requestToken);
     $url = $twitter->url('oauth/authorize', array('oauth_token' => $this->session->getTMP('twitter_request_token')['oauth_token']));
     return $url;
 }
Beispiel #13
0
 private function _redirectFlow()
 {
     $conn = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
     //リクエストトークンをセットする、コールバックURKを渡す
     $tokens = $conn->oauth('oauth/request_token', ['oauth_callback' => CALLBACK_URL]);
     // 後で利用できるようにsessionに保存する
     $_SESSION['oauth_token'] = $tokens['oauth_token'];
     $_SESSION['oauth_token_secret'] = $tokens['oauth_token_secret'];
     // redirect アカウントの利用を許可しますか?へ飛ばす
     $authorizeUrl = $conn->url('oauth/authorize', ['oauth_token' => $tokens['oauth_token']]);
     header('Location: ' . $authorizeUrl);
     exit;
 }
Beispiel #14
0
 public function getauthorizeurl()
 {
     $ret = null;
     $twitter_oauth_callback = site_url('user/signup');
     $connection = new TwitterOAuth($this->twitter_app_id, $this->twitter_api_secret);
     $connection->setTimeouts(10, 15);
     //To prevent timeout error
     $request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => $twitter_oauth_callback));
     $_SESSION['oauth_token'] = $request_token['oauth_token'];
     $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
     $ret = $connection->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token']));
     return $ret;
 }
Beispiel #15
0
 private function _redirectFlow()
 {
     $conn = new TwitterOAuth(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET);
     // 認証リクエスト用トークン発行
     $tokens = $conn->oauth('oauth/request_token', ['oauth_callback' => TWITTER_CALLBACK_URL]);
     // 認証リクエスト用トークンの保持
     $_SESSION['tmp_twitter_oauth_token'] = $tokens['oauth_token'];
     $_SESSION['tmp_twitter_oauth_token_secret'] = $tokens['oauth_token_secret'];
     // Twitterの認証画面へリダイレクトさせる
     $authorizeUrl = $conn->url('oauth/authorize', ['oauth_token' => $tokens['oauth_token']]);
     header('Location: ' . $authorizeUrl);
     exit;
 }
 public function displaySignin()
 {
     $callback_url = $this->getFunctionUrl('Auth', 'signin');
     $connection = new TwitterOAuth(consumer_key, consumer_secret);
     // request token sementara, sebelum user login, simpan ke sessions
     $requestToken = $connection->oauth('oauth/request_token', array('oauth_callback' => $callback_url));
     $_SESSION['oauth_token'] = $requestToken['oauth_token'];
     $_SESSION['oauth_token_secret'] = $requestToken['oauth_token_secret'];
     // get url dari token sementara
     $url = $connection->url('oauth/authorize', array('oauth_token' => $requestToken['oauth_token']));
     // render
     $this->render('signin', ['signinUrl' => $url]);
     return true;
 }
Beispiel #17
0
 public function authorize()
 {
     $twitteroauth = new TwitterOAuth(tw_consumer_key, tw_consumer_secret);
     $request_token = $twitteroauth->oauth('oauth/request_token', array('oauth_callback' => tw_url_callback));
     // if($twitteroauth->getLastHttpCode() != 200) {
     //   throw new \Exception('There was a problem performing this request');
     // }
     session::init();
     session::set('tw_oauth_token', $request_token['oauth_token']);
     session::set('tw_oauth_token_secret', $request_token['oauth_token_secret']);
     // session::set('dede','sasdasd');
     $url = $twitteroauth->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token']));
     // and redirect
     header('Location: ' . $url);
 }
 public function connect()
 {
     $oauth_access_token = "4024026614-YzNlvVqSSGbG3kNR9Nik4aoyKy9zpCugloyVm8H";
     $oauth_access_token_secret = "zJAhBgxyOQQYICCM1o908EVFAPJKQwWkNM6jkmny3rrP7";
     $consumer_key = "LEqoRF6gLyLPxIFlGDjze5xd0";
     // For Offerz-develop app
     $consumer_secret = "c0B582T95BFWUUzR2UnOFqWb2RaDQpQ1BH7qPC0aD7w1cf6hVR";
     // echo SITE_URL; die;
     //	$connection = new TwitterOAuth($consumer_key, $consumer_secret,$oauth_access_token,$oauth_access_token_secret);
     $connection = new TwitterOAuth($consumer_key, $consumer_secret);
     $request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => SITE_URL . "client/callback_twitter"));
     $url = $connection->url("oauth/authorize", array("oauth_token" => $request_token['oauth_token']));
     //header('Location: '. $url);
     // die('--333');
     return $url;
 }
 public function loginTwitter($data)
 {
     if (!Session::has('access_token')) {
         $connection = new TwitterOAuth(config('socialpack.composer_key'), config('socialpack.composer_secret'));
         $callback_url = url('/') . '/callbackTwitter';
         $request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => (string) $callback_url));
         Session::put('oauth_token', $request_token['oauth_token']);
         Session::put('oauth_token_secret', $request_token['oauth_token_secret']);
         $url = $connection->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token']));
         return redirect()->away($url);
     } else {
         $access_token = Session::get('access_token');
         $connection = new TwitterOAuth(config('socialpack.composer_key'), config('socialpack.composer_secret'), $access_token['oauth_token'], $access_token['oauth_token_secret']);
         if (isset($data) && !empty($data)) {
             if (isset($data['profile']) && !empty($data['profile'])) {
                 if ($data['profile'] == "yes") {
                     // getting basic user info
                     $user = $connection->get("account/verify_credentials");
                     return $user;
                 }
             }
             if (isset($data['post_tweet']) && !empty($data['post_tweet'])) {
                 if ($data['post_tweet']["show"] == "yes") {
                     // posting tweet on user profile
                     $post = $connection->post('statuses/update', array('status' => $data['post_tweet']["message"]));
                     return $post;
                 }
             }
             if (isset($data['recent_tweets']) && !empty($data['recent_tweets'])) {
                 if ($data['recent_tweets']["show"] == "yes") {
                     // getting recent tweeets by user 'snowden' on twitter
                     $tweets = $connection->get('statuses/user_timeline', ['count' => 200, 'exclude_replies' => true, 'screen_name' => 'snowden', 'include_rts' => false]);
                     $totalTweets[] = $tweets;
                     $page = 0;
                     for ($count = 200; $count < 500; $count += 200) {
                         $max = count($totalTweets[$page]) - 1;
                         $tweets = $connection->get('statuses/user_timeline', ['count' => 200, 'exclude_replies' => true, 'max_id' => $totalTweets[$page][$max]->id_str, 'screen_name' => 'snowden', 'include_rts' => false]);
                         $totalTweets[] = $tweets;
                         $page += 1;
                     }
                     return $totalTweets;
                 }
             }
         }
     }
 }
Beispiel #20
0
 public function goToLoginPage()
 {
     $twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
     // リクエストトークン取得
     $token = $twitter->oauth('oauth/request_token', array('oauth_callback' => CALLBACK_URL));
     if (!isset($token['oauth_token'])) {
         echo "エラー発生";
         exit;
     }
     $request_token = $token['oauth_token'];
     session_start();
     $_SESSION['request_token_secret'] = $token['oauth_token_secret'];
     // ログインURLを取得してリダイレクト
     $url = $twitter->url("oauth/authenticate", array("oauth_token" => $request_token));
     header('Location: ' . $url);
     exit;
 }
 /**
  * @return void
  * @throws \Exception
  */
 public function execute()
 {
     /* Build TwitterOAuth object with client credentials. */
     $connection = new TwitterOAuth($this->_oAuthkey, $this->_oAuthsecret);
     /* Get temporary credentials. */
     $request_token = $connection->oauth('oauth/request_token', ['oauth_callback' => $this->_objectManager->get('Magento\\Framework\\Url')->getUrl('twitterfeed/oauth/callback', [])]);
     /* If last connection failed don't display authorization link. */
     if (200 == $connection->getLastHttpCode()) {
         $this->_objectManager->get('Magento\\Framework\\App\\MutableScopeConfig')->setValue('sama_twitterfeed/oauth/token', $request_token['oauth_token']);
         $this->_objectManager->get('Magento\\Framework\\App\\MutableScopeConfig')->setValue('sama_twitterfeed/oauth/token_secret', $request_token['oauth_token_secret']);
         /* Build authorize URL and redirect user to Twitter. */
         $url = $connection->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token']));
         header('location: ' . $url);
         exit;
     } else {
         throw new Exception("Twitter Oauth API status code: {$connection->getLastHttpCode()}");
     }
 }
Beispiel #22
0
 function redirectToTwitter()
 {
     if (isset($_GET['token_id'])) {
         $_SESSION['TATAG_TOKEN_ID'] = $_GET['token_id'];
     }
     if (isset($_GET['otk'])) {
         $_SESSION['TATAG_OTK'] = $_GET['otk'];
     }
     if (isset($_GET['next'])) {
         $_SESSION['TATAG_NEXT'] = $_GET['next'];
     }
     $oauth = new TwitterOAuth(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET);
     $token = $oauth->oauth("oauth/request_token", array("oauth_callback" => HOME . '/login_tw.php'));
     if (!$token or !$token['oauth_token']) {
         Error::http(500, json_encode($requestToken));
     }
     // Saving them into the session
     $_SESSION['oauth_token'] = $token['oauth_token'];
     $_SESSION['oauth_token_secret'] = $token['oauth_token_secret'];
     // Let's generate the URL and redirect
     $url = $oauth->url('oauth/authorize', array('oauth_token' => $token['oauth_token']));
     //print_r($_SESSION); exit();
     header('Location: ' . $url);
 }
Beispiel #23
0
<?php

session_start();
require_once 'common.php';
require_once 'twitteroauth-0.4.1/autoloader.php';
use Abraham\TwitterOAuth\TwitterOAuth;
//TwitterOAuth をインスタンス化
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
//コールバックURLをここでセット
$request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => OAUTH_CALLBACK));
//callback.phpで使うのでセッションに入れる
$_SESSION['oauth_token'] = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
//Twitter.com 上の認証画面のURLを取得
$url = $connection->url('oauth/authenticate', array('oauth_token' => $request_token['oauth_token']));
//Twitter.com の認証画面へリダイレクト
header('location: ' . $url);
session_start();
// require libraries
require_once 'app/includes/libs/twitteroauth/autoload.php';
use Abraham\TwitterOAuth\TwitterOAuth;
$consumer_key = 'Sgym1Ov9J4opgdB7gNtQHC0tP';
$consumer_secret = '5icBNUmq3GcWhT7seMzD34SLMBhAXbCDMBQiOBe4sqZ9gEiXrw';
$callback_url = 'http://localhost/sit/tugasAkhir/oauthtest.php';
echo isset($_REQUEST['oauth_token']);
if (!isset($_REQUEST['oauth_token'])) {
    $connection = new TwitterOAuth($consumer_key, $consumer_secret);
    // request token sementara, sebelum suer login
    $requestToken = $connection->oauth('oauth/request_token', array('oauth_callback' => $callback_url));
    $_SESSION['oauth_token'] = $requestToken['oauth_token'];
    $_SESSION['oauth_token_secret'] = $requestToken['oauth_token_secret'];
    $url = $connection->url('oauth/authorize', array('oauth_token' => $requestToken['oauth_token']));
    echo "<a href='{$url}'>Login</a>";
} else {
    // cek jika token sementara yng sebelumnya sama dengan yang dikirim ke twitter
    $request_token = [];
    $request_token['oauth_token'] = $_SESSION['oauth_token'];
    $request_token['oauth_token_secret'] = $_SESSION['oauth_token_secret'];
    if (isset($_REQUEST['oauth_token']) && $request_token['oauth_token'] !== $_REQUEST['oauth_token']) {
        echo "Error.";
        exit;
    }
    // instance twitteroauth dengan temporary request token
    $connection = new TwitterOAuth($consumer_key, $consumer_secret, $request_token['oauth_token'], $request_token['oauth_token_secret']);
    // get access token
    $access_token = $connection->oauth("oauth/access_token", array("oauth_verifier" => $_REQUEST['oauth_verifier']));
    $_SESSION['access_token'] = $access_token;
    define('SITE_URL', "http://" . $host . "/offerz/");
} else {
    define('SITE_URL', "http://" . $host . "/");
}
$oauth_access_token = "4024026614-YzNlvVqSSGbG3kNR9Nik4aoyKy9zpCugloyVm8H";
$oauth_access_token_secret = "zJAhBgxyOQQYICCM1o908EVFAPJKQwWkNM6jkmny3rrP7";
$consumer_key = "LEqoRF6gLyLPxIFlGDjze5xd0";
// For Offerz-develop app
$consumer_secret = "c0B582T95BFWUUzR2UnOFqWb2RaDQpQ1BH7qPC0aD7w1cf6hVR";
// echo SITE_URL; die;
//	$connection = new TwitterOAuth($consumer_key, $consumer_secret,$oauth_access_token,$oauth_access_token_secret);
$connection = new TwitterOAuth($consumer_key, $consumer_secret);
// $content = $connection->get("account/verify_credentials");
// print_r($content ); die('eee');
//$tweets = $connection->get("friends/ids", array("screen_name" => "vishal_betasoft"));
// Requesting authentication tokens, the parameter is the URL we will be redirected to
// $request_token = $connection->post('https://api.twitter.com/oauth/request_token');
//print_r($tweets ); die('ee');
// $access_token = $connection->oauth("oauth/access_token", array("oauth_verifier" => ""));
// $request_token = $connection->oauth('http://betasoftdev.com/darren/callback.php');
$request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => SITE_URL . "callback.php"));
//print_r($access_token );
// die('eteee');
//if($connection ->http_code==200){
// Let's generate the URL and redirect
$url = $connection->url("oauth/authorize", array("oauth_token" => $request_token['oauth_token']));
header('Location: ' . $url);
//} else {
// It's a bad idea to kill the script, but we've got to know when there's an error.
// die('Something wrong happened.');
// }
Beispiel #26
0
				);

			switch ($_GET['mode']) {
				case 'host':
					$_SESSION["cbpage"] = "accounts.php";
					break;
				case 'client':
					$_SESSION["cbpage"] = "index.html";
					break;
				default:
					# code...
					break;
			}

			$option = array('oauth_callback' => $callback);

			$request_token = $twitter_oauth->oauth('oauth/request_token', $option);
			$_SESSION['oauth_token'] = $request_token["oauth_token"];
			$_SESSION['oauth_token_secret'] = $request_token["oauth_token_secret"];

			$url = $twitter_oauth->url('oauth/authenticate', array('oauth_token' => $request_token["oauth_token"]));
			if($_GET["force_login"] == "true")
			{
				$url .= "&force_login=true";
			}

			header('location: '.$url);
			return;
		?>
</head>
</http>
 public function testUrl()
 {
     $url = $this->twitter->url('oauth/authorize', array('foo' => 'bar', 'baz' => 'qux'));
     $this->assertEquals('https://api.twitter.com/oauth/authorize?foo=bar&baz=qux', $url);
 }
Beispiel #28
0
 /**
  * Build and return the client URL for authentication
  *
  * @return string
  */
 public function getRedirectUrl()
 {
     $token = $this->getRequestToken();
     $redirectUrl = $this->client->url('oauth/authenticate', array('oauth_token' => $token['oauth_token']));
     return $redirectUrl;
 }
Beispiel #29
0
?>
><a href="?yourquestions">Your questions</a></li>
<?php 
// User login
if (!isset($_SESSION['access_token']) || !isset($_SESSION['access_token_secret'])) {
    if (isset($_GET['oauth_verifier'])) {
        $access_token = $connection->oauth("oauth/access_token", array("oauth_verifier" => $_GET['oauth_verifier'], "oauth_token" => $_GET['oauth_token']));
        $_SESSION['access_token'] = $access_token['oauth_token'];
        $_SESSION['access_token_secret'] = $access_token['oauth_token_secret'];
        $_SESSION['screen_name'] = $access_token['screen_name'];
        print "<div class=\"alert alert-success\" role=\"alert\" style=\"position: fixed;\" top=\"60px\"><strong>WEOW!</strong> Successfully logged in as @" . $access_token['screen_name'] . ". <a href=" . $base_url . ">Click here to continue.</a></div>";
        header("Location: http://localhost/");
        exit;
    } else {
        $access_token = $connection->oauth("oauth/request_token", array("oauth_callback" => $base_url));
        $url = $connection->url("oauth/authenticate", array("oauth_token" => $access_token['oauth_token']));
        print "<p align=right>You are not logged in. <a href=\"" . $url . "\">Log in with Twitter!</a></p>";
    }
} else {
    // Handle log outs
    if (isset($_GET['logout'])) {
        session_destroy();
        //print("<p align=right>You have logged out. <a href=index.php>Return</a></p>");
        print "<div class=\"alert alert-success\" role=\"alert\" style=\"position: fixed;\" top=\"-200px\">You have logged out. <a href=index.php>Return</a></div>";
        exit;
    }
    $userscreenname = $_SESSION['screen_name'];
    //print_r($content); // DEBUG
    print "<p align=right>You are logged in as @" . $userscreenname . " <a href=\"?logout\">Log out.</a></p>";
    $logged_in = true;
}
Beispiel #30
0
/**
 *
 * This function is for authentication of the user to twitter server.
 * You should call this function at the beginning of the page before anything else.
 * If the user is not logged in, it will display a login link that by clicking on it
 * user will be redirected to twitter login page. Once user came back, this function will put the access the token in the session.
 *
 * If the access token is in the session, it will not make a call to twitter api again!
 *
 * if not logged in
 * @return null + echos a login link
 * if logged in
 * @return access_token
 * @throws \Abraham\TwitterOAuth\TwitterOAuthException
 */
function authorizationTwitterUser()
{
    $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
    if (isset($_REQUEST['oauth_token']) && !empty($_REQUEST['oauth_token']) && isset($_REQUEST['oauth_verifier']) && !empty($_REQUEST['oauth_verifier'])) {
        if (isset($_REQUEST['oauth_token']) && $_SESSION['oauth_token'] !== $_REQUEST['oauth_token']) {
            echo "oauth token is not the same as request token.";
            session_destroy();
        }
        if (!isset($_SESSION['access_token']) || empty($_SESSION['access_token'])) {
            $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
            try {
                $access_token = $connection->oauth("oauth/access_token", array("oauth_verifier" => $_REQUEST['oauth_verifier']));
                $_SESSION['access_token'] = $access_token;
            } catch (Abraham\TwitterOAuth\TwitterOAuthException $e) {
                echo "The returned oauth token is not valid.";
            }
        }
        return $_SESSION['access_token'];
    } else {
        if (isset($_SESSION['access_token']) && !empty($_SESSION['access_token'])) {
            return $_SESSION['access_token'];
        } else {
            $request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => REDIRECT_URI));
            $_SESSION['oauth_token'] = $request_token['oauth_token'];
            $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
            $url = $connection->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token']));
            echo "<a href={$url}>login</a>";
            return null;
        }
    }
}