Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
68 lines (56 sloc) 1.83 KB
<?php
include('inc.php');
require_once('EpiCurl.php');
require_once('EpiOAuth.php');
require_once('EpiTwitter.php');
include('templates/header.php');
$twitter = new EpiTwitter(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET);
if(get('oauth_token'))
{
// Returned from the Twitter approval screen
$twitter->setToken(get('oauth_token'));
try
{
$token = $twitter->getAccessToken(array('oauth_verifier'=>get('oauth_verifier')));
if($token->oauth_token && $token->oauth_token_secret)
{
$twitter = new EpiTwitter(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, $token->oauth_token, $token->oauth_token_secret);
// User successfully authenticated to Twitter.
$account = $twitter->get_accountVerify_credentials();
$user->addTwitterInfo($account->screen_name, $account->id, $token->oauth_token, $token->oauth_token_secret);
header('Location: /twitter_connect?confirmed');
die();
}
else
login_error('Twitter Error', 'No tokens were provided in the response from Twitter.');
}
catch(EpiOAuthException $e)
{
login_error('Twitter Error', 'Unable to get an access token. Probably your request token has expired. Try logging in again.');
}
}
else if(array_key_exists('confirmed', $_GET)) {
?>
<div style="text-align: center;">
<div style="font-size: 14pt; width: 190px; margin: 40px auto;">Looks good! You can go back to your<br /><a href="/list">list of graphs</a>.</div>
</div>
<?php
}
else
{
try
{
$auth_url = $twitter->getAuthorizeUrl(null, array('oauth_callback' => https() . $_SERVER['SERVER_NAME'] . '/twitter_connect'));
}
catch(EpiOAuthException $e)
{
login_error('Twitter Error', 'Unable to get the authentication URL from Twitter: ' . $e->getMessage());
}
header('Location: ' . $auth_url);
die();
}
include('templates/footer.php');
function login_error($title, $message) {
echo $title . ' ' . $message;
die();
}