I am trying to integrate twitter Sign-in with slim framework using the twitteroauth PHP API. I have divided my index page by including several modules as in login, register, users in different files and calling it here on index at the top.
my index page is redirected to fb log-in there after i store session for fb and check it in all the modules using an middleware function $authorize.
Anyways my twitter sign-in code is in the user page that is visible after successful fb sign-in.
Also i render my page to jquery mobile framework.
twitter button code i.e inside /user/me.
<a class="twitterSignInButton" rel="external" href="twitterlogininit/"></a>
twitter sign-in code i.e inside users.php
$app->get('/user/me/twitterlogininit/',function() use ($app){
$request_token=$app->twitter->getRequestToken('http://<domain>/App/user/me/twitterlogin/');
$_SESSION['oauth_token']=$request_token['oauth_token'];
$_SESSION['oauth_token_secret']=$request_token['oauth_token_secret'];
if($app->twitter->http_code==200){
// Let's generate the URL and redirect
$url = $app->twitter->getAuthorizeURL($request_token['oauth_token']);
$app->redirect($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.');
}
});
//twitter redirect
$app->get('/user/me/twitterlogin/',function() use ($app){
if(!empty($_GET['oauth_verifier']) && !empty($_SESSION['oauth_token']) && !empty($_SESSION['oauth_token_secret'])){
$app->twitteroauth = new TwitterOAuth('xxxxx', 'xxxxx', $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
$access_token = $app->twitteroauth->getAccessToken($_GET['oauth_verifier']);
$_SESSION['access_token'] = $access_token;
$user_info = $app->twitteroauth->get('account/verify_credentials');
print_r($user_info);
} else {
// Something's missing, go back to square 1
}
});
And the error im getting is
Slim Application Error
The application could not run because of the following error:
Details:
Message: Undefined index: oauth_token
File: /var/www/html/FoodKite/App/Libs/Twitter/twitteroauth.php
Line: 118
Stack Trace:
#0 /var/www/html/FoodKite/App/Libs/Twitter/twitteroauth.php(118): Slim::handleErrors(8, 'Undefined index...', '/var/www/html/F...', 118, Array)
#1 /var/www/html/FoodKite/App/Modules/Users.php(172): TwitterOAuth->getAccessToken('yiIL1eyvwGVOrQI...')
#2 [internal function]: {closure}()
#3 /var/www/html/FoodKite/App/Slim/Route.php(392): call_user_func_array(Object(Closure), Array)
#4 /var/www/html/FoodKite/App/Slim/Slim.php(1051): Slim_Route->dispatch()
#5 /var/www/html/FoodKite/App/index.php(154): Slim->run()
#6 {main}
after lots of search i found prolly its twitter reject req. because of timestamp. Still can find any workaround
upadate:
i added all the code on the index.php before facebook login. it works just fine. with the button on the home page.
now if i add the button to the page i want i.e. /user/app with the same code that of home page it gives the same error i guess slim is a confloc now. i read it somewhere regarding the slim session handling can that be one of the problems?