Timeout problems with Abraham's twitter API auth

oauth
api

#1

Hi, I have timeout problems on my both test labs. Problems started before two days (I was editing my MVC based test server independently to the other test lab) on both my labs. Whats wrong here? :confused:
TwitterController.php

    namespace Controllers;
    use Abraham\TwitterOAuth\TwitterOAuth;
    
    class TwitterController extends Controller
    {
        public function process($params)
        {
            if(isset($params[0]) && $params[0] == 'logout') {
                unset($_SESSION['oauth_token']);
                unset($_SESSION['oauth_verifier']);
                $this->redirect('home');
            }
            if(isset($_SESSION['oauth_token'])) {
                $consumer_key = 'xx';
                $consumer_secret = 'xx';
                $connection = new TwitterOAuth($consumer_key, $consumer_secret);
                $connection->setTimeouts(10,15);
                //necessary to get access token other wise u will not have permision to get user info
                $params=array("oauth_verifier" => $_GET['oauth_verifier'],"oauth_token"=>$_GET['oauth_token']);
                $access_token = $connection->oauth("oauth/access_token", $params);
                //now again create new instance using updated return oauth_token and oauth_token_secret because old one expired if u dont u this u will also get token expired error
                $connection = new TwitterOAuth($consumer_key, $consumer_secret,
                    $access_token['oauth_token'],$access_token['oauth_token_secret']);
                $connection->setTimeouts(10,15);
                $content = $connection->get("account/verify_credentials");
                $timelineContent = $connection->get("statuses/user_timeline", ['count' => 50, 'include_rts' => 1]);
                $_SESSION['twitter_data'][] = (array)$content;
                $_SESSION['twitter_data'][] = (array)$timelineContent;
                var_dump($_SESSION['twitter_data']);
                $this->redirect('home');
            }
            else{
                // main startup code
                $consumer_key = 'xx';
                $consumer_secret = 'xx';
                //this code will return your valid url which u can use in iframe src to popup or can directly view the page as its happening in this example
                $connection = new TwitterOAuth($consumer_key, $consumer_secret);
                $temporary_credentials = $connection->oauth('oauth/request_token', array("oauth_callback" =>'http://idelab.tk/twitter'));
                $_SESSION['oauth_token']=$temporary_credentials['oauth_token'];
                $_SESSION['oauth_token_secret']=$temporary_credentials['oauth_token_secret'];
                $url = $connection->url("oauth/authorize", array("oauth_token" => $temporary_credentials['oauth_token']));
                // REDIRECTING TO THE URL
                header('Location: ' . $url);
            }
        }
    }

and browser is somethin like this

Fatal error: Uncaught exception ‘Abraham\TwitterOAuth\TwitterOAuthException’ with message ‘Connection timed out after 5001 milliseconds’ in /var/home/idelab.tk/public_html/Models/Abraham/TwitterOAuth/TwitterOAuth.php:408 Stack trace: #0 /var/home/idelab.tk/public_html/Models/Abraham/TwitterOAuth/TwitterOAuth.php(334): Abraham\TwitterOAuth\TwitterOAuth->request(‘https://api.twi…’, ‘POST’, ‘Authorization: …’, Array) #1 /var/home/idelab.tk/public_html/Models/Abraham/TwitterOAuth/TwitterOAuth.php(135): Abraham\TwitterOAuth\TwitterOAuth->oAuthRequest(‘https://api.twi…’, ‘POST’, Array) #2 /var/home/idelab.tk/public_html/Controllers/TwitterController.php(74): Abraham\TwitterOAuth\TwitterOAuth->oauth(‘oauth/request_t…’, Array) #3 /var/home/idelab.tk/public_html/Controllers/RouterController.php(31): Controllers\TwitterController->process(Array) #4 /var/home/idelab.tk/public_html/index.php(25): Controllers\RouterController->process(Array) #5 {main} thrown in /var/home/idelab.tk/public_html/Models/Abraham/TwitterOAuth/TwitterOAuth.php on line 408

Sorry for that messy code. I promise, that i will fix it in next version :slight_smile: