Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix for the api end point #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Bug fix for the api end point #2

wants to merge 1 commit into from

Conversation

rayfranco
Copy link

Hi,

It seems that you misspell the new authorization URL, so I just did a fix for my needs, wanted to share what fixes it.
The bug was that it keeps asking for authorization each time we loose the session, even if the connexion was successful the first time.

Cheers, and good job !

@elliothaughin
Copy link
Owner

I though the endpoint was already correct?

"The endpoint for the authorization url is https://api.twitter.com/oauth/authorize. It must have a single query parameter attached called oauth_token with the value set to the oauth_token you received in the request token step"

http://dev.twitter.com/pages/auth

@rayfranco
Copy link
Author

Actually, is this works without the https ? Maybe you are right, but this fixed the issue for sure, at least in my case :)
Have you tried it ? Does it works well in your version ?
Cheers

@elliothaughin
Copy link
Owner

"The bug was that it keeps asking for authorization each time we loose the session, even if the connexion was successful the first time."

I'm not exactly what you mean. Could you describe the bug a bit more?
Maybe a set of steps that demonstrate what happens and what the expected behaviour is?

@rayfranco
Copy link
Author

Sorry about my english,

Maybe it's due to the use of this library I have, but I need the user to sign-in, maybe this method is made for something else ? I refer to this page that gave me the solution :

http://dev.twitter.com/pages/sign_in_with_twitter

Then

http://dev.twitter.com/doc/get/oauth/authenticate

That says : _for applications using the Sign in with Twitter authentication flow. The method will use the currently logged in user as the account for access authorization_

So the bug was that each time users tried to log in to my application, twitter was making a new authorization request, and were unable to recognize the user, even if he already give its authorization once.

Hope this is more clear.

@mustafakhimani
Copy link

What were the bugs and how did u fix it. I am getting a similar problem. It keeps asking for permission again and again. Can you help me, with what should be the changes made and where

@rayfranco
Copy link
Author

Hi,

It seems that Eliott did not accept the pull yet, you can get the fix there : RayFranco/codeigniter-twitter@eef8b68e992635e72b1e464c0fb0e212b8219318

Good luck

@hackmyway
Copy link

Hi,

i am facing the same issues even after applying the fix.

checkout http://www.jobiance.com/tweet_test/

Is anything missing ?

Please help. It's urgent!

Abhay

@cdevroe
Copy link

cdevroe commented Apr 13, 2011

I don't know if this Pull Request will fix my issue, but I am being redirected back to Twitter every single time. I've already merged in @rayfranco's eef8b68 commit.

@hackmyway
Copy link

Hi cdevroe,

Seems you are struggling big time.
I applied fix mentioned by elliothaughin .

Check your curl libraries .

Check if your php framework supports Query Strings (e.g. http://www.hireplug.com?authorize_url=www.fbapp.hireplug.com

I was using codeigniter and codeiginter by default supports segment urls not query strings.
I had to configure codeigniter so that it supports query strings.
After this change twitter authorization was working properly.

Here's my tweet working library for your reference.
class tweet {

    private $_oauth = NULL;

    function __construct()        
    {
        $this->_oauth = new tweetOauth();
    }

    function __call($method, $args)
    {
        if ( method_exists($this, $method) )
        {
            return call_user_func_array(array($this, $method), $args);
        }

        return call_user_func_array(array($this->_oauth, $method), $args);
    }

    function logged_in()
    {
        return $this->_oauth->loggedIn();
    }

    function set_callback($url)
    {
        $this->_oauth->setCallback($url);
    }

    function login()
    {
        return $this->_oauth->login();
    }

    function logout()
    {
        return $this->_oauth->logout();
    }

    function get_tokens()
    {
        $tokens = array(
                        'oauth_token' => $this->_oauth->getAccessKey(),
                        'oauth_token_secret' => $this->_oauth->getAccessSecret()
                    );

        return $tokens;
    }

    function set_tokens($tokens)
    {
        return $this->_oauth->setAccessTokens($tokens);
    }
}

class tweetException extends Exception {

    function __construct($string)
    {
        parent::__construct($string);
    }

    public function __toString() {
        return "exception '".__CLASS__ ."' with message '".$this->getMessage()."' in ".$this->getFile().":".$this->getLine()."\nStack trace:\n".$this->getTraceAsString();
    }
}

class tweetConnection {

    // Allow multi-threading.

    private $_mch = NULL;
    private $_properties = array();

    function __construct()
    {
        $this->_mch = curl_multi_init();

        $this->_properties = array(
            'code'      => CURLINFO_HTTP_CODE,
            'time'      => CURLINFO_TOTAL_TIME,
            'length'    => CURLINFO_CONTENT_LENGTH_DOWNLOAD,
            'type'      => CURLINFO_CONTENT_TYPE
        );
    }

    private function _initConnection($url)
    {
        $this->_ch = curl_init($url);
        curl_setopt($this->_ch, CURLOPT_RETURNTRANSFER, TRUE);
    }

    public function get($url, $params)
    {
        if ( count($params['request']) > 0 )
        {
            $url .= '?';

            foreach( $params['request'] as $k => $v )
            {
                $url .= "{$k}={$v}&";
            }

            $url = substr($url, 0, -1);
        }

        $this->_initConnection($url);
        $response = $this->_addCurl($url, $params);

        return $response;
    }

    public function post($url, $params)
    {
        // Todo
        $post = '';

        foreach ( $params['request'] as $k => $v )
        {
            $post .= "{$k}={$v}&";
        }

        $post = substr($post, 0, -1);

        $this->_initConnection($url, $params);
        curl_setopt($this->_ch, CURLOPT_POST, 1);
        curl_setopt($this->_ch, CURLOPT_POSTFIELDS, $post);

        $response = $this->_addCurl($url, $params);

        return $response;
    }

    private function _addOauthHeaders(&$ch, $url, $oauthHeaders)
    {
        $_h = array('Expect:');
        $urlParts = parse_url($url);
        $oauth = 'Authorization: OAuth realm="' . $urlParts['path'] . '",';

        foreach ( $oauthHeaders as $name => $value )
        {
            $oauth .= "{$name}=\"{$value}\",";
        }

        $_h[] = substr($oauth, 0, -1);

        curl_setopt($ch, CURLOPT_HTTPHEADER, $_h);
    }

    private function _addCurl($url, $params = array())
    {
        if ( !empty($params['oauth']) )
        {
            $this->_addOauthHeaders($this->_ch, $url, $params['oauth']);
        }

        $ch = $this->_ch;

        $key = (string) $ch;
        $this->_requests[$key] = $ch;

        $response = curl_multi_add_handle($this->_mch, $ch);

        if ( $response === CURLM_OK || $response === CURLM_CALL_MULTI_PERFORM )
        {
            do {
                $mch = curl_multi_exec($this->_mch, $active);
            } while ( $mch === CURLM_CALL_MULTI_PERFORM );

            return $this->_getResponse($key);
        }
        else
        {
            return $response;
        }
    }

    private function _getResponse($key = NULL)
    {
        if ( $key == NULL ) return FALSE;

        if ( isset($this->_responses[$key]) )
        {
            return $this->_responses[$key];
        }

        $running = NULL;

        do
        {
            $response = curl_multi_exec($this->_mch, $running_curl);

            if ( $running !== NULL && $running_curl != $running )
            {
                $this->_setResponse($key);

                if ( isset($this->_responses[$key]) )
                {
                    $response = new tweetResponseOauth( (object) $this->_responses[$key] );

                    if ( $response->__resp->code !== 200 )
                    {
                        throw new tweetException($response->__resp->code.' | Request Failed: '.$response->__resp->data->request.' - '.$response->__resp->data->error);
                    }

                    return $response;
                }
            }

            $running = $running_curl;

        } while ( $running_curl > 0);

    }

    private function _setResponse($key)
    {
        while( $done = curl_multi_info_read($this->_mch) )
        {
            $key = (string) $done['handle'];
            $this->_responses[$key]['data'] = curl_multi_getcontent($done['handle']);

            foreach ( $this->_properties as $curl_key => $value )
            {
                $this->_responses[$key][$curl_key] = curl_getinfo($done['handle'], $value);

                curl_multi_remove_handle($this->_mch, $done['handle']);
            }
      }
    }
}

class tweetResponseOauth {

    private $__construct;

    public function __construct($resp)
    {
        $this->__resp = $resp;

        if ( strpos($this->__resp->type, 'json') !== FALSE )
        {
            $this->__resp->data = json_decode($this->__resp->data);
        }
    }

    public function __get($name)
    {
        if ($this->__resp->code < 200 || $this->__resp->code > 299) return FALSE;

        if ( is_string($this->__resp->data ) )
        {
            parse_str($this->__resp->data, $result);
        }
        else
        {
            $result = $this->__resp->data;
        }

        foreach($result as $k => $v)
        {
            $this->$k = $v;
        }

        if ( $name === '_result')
        {
            return $result;
        }

        return $result[$name];
    }
}

class tweetOauth extends tweetConnection {

    private $_obj;
    private $_tokens = array();
    private $_authorizationUrl  = 'http://api.twitter.com/oauth/authorize';
    //private $_authorizationUrl  = 'http://api.twitter.com/oauth/authenticate';
    private $_requestTokenUrl   = 'http://api.twitter.com/oauth/request_token';
    private $_accessTokenUrl    = 'http://api.twitter.com/oauth/access_token';
    private $_signatureMethod   = 'HMAC-SHA1';
    private $_version           = '1.0';
    private $_apiUrl            = 'http://api.twitter.com';
    private $_searchUrl         = 'http://search.twitter.com/';
    private $_callback = NULL;
    private $_errors = array();
    private $_enable_debug = FALSE;

    function __construct()
    {
        parent::__construct();

        $this->_obj =& get_instance();
        $this->_obj->load->config('tweet');
        $this->_obj->load->library('session');
        $this->_obj->load->library('unit_test');
        $this->_obj->load->helper('url');

        $this->_tokens =    array(
                                'consumer_key'      => $this->_obj->config->item('tweet_consumer_key'),
                                'consumer_secret'   => $this->_obj->config->item('tweet_consumer_secret'),
                                'access_key'        => $this->_getAccessKey(),
                                'access_secret'     => $this->_getAccessSecret()
                            );

        $this->_checkLogin();
    }

    function __destruct()
    {
        if ( !$this->_enable_debug ) return;

        if ( !empty($this->_errors) )
        {
            foreach ( $this->_errors as $key => $e )
            {
                echo '<pre>'.$e.'</pre>';
            }
        }
    }

    public function enable_debug($debug)
    {
        $debug = (bool) $debug;
        $this->_enable_debug = $debug;
    }

    public function call($method, $path, $args = NULL)
    {
        $response = $this->_httpRequest(strtoupper($method), $this->_apiUrl.'/'.$path.'.json', $args);

        // var_dump($response);
        // die();

        return ( $response === NULL ) ? FALSE : $response->_result;
    }

    public function search($args = NULL)
    {
        $response = $this->_httpRequest('GET', $this->_searchUrl.'search.json', $args);

        return ( $response === NULL ) ? FALSE : $response->_result;
    }

    public function loggedIn()
    {
        $access_key = $this->_getAccessKey();
        $access_secret = $this->_getAccessSecret();

        $loggedIn = FALSE;

        if ( $this->_getAccessKey() !== NULL && $this->_getAccessSecret() !== NULL )
        {
            $loggedIn = TRUE;
        }

        $this->_obj->unit->run($loggedIn, TRUE, 'Logged In');
        return $loggedIn;
    }

    private function _checkLogin()
    {
        if ( isset($_GET['oauth_token']) )
        {
            $this->_setAccessKey($_GET['oauth_token']);
            $token = $this->_getAccessToken();

            $token = $token->_result;

            $token = ( is_bool($token) ) ? $token : (object) $token;

            if ( !empty($token->oauth_token) && !empty($token->oauth_token_secret) )
            {
                $this->_setAccessKey($token->oauth_token);
                $this->_setAccessSecret($token->oauth_token_secret);
            }

            redirect(current_url());
            return NULL;
        }
    }

    public function login()
    {
        if ( ($this->_getAccessKey() === NULL || $this->_getAccessSecret() === NULL) )
        {
            header('Location: '.$this->_getAuthorizationUrl());
            return;
        }

        return $this->_checkLogin();
    }

    public function logout()
    {
        $this->_obj->session->unset_userdata('twitter_oauth_tokens');
    }

    public function getTokens()
    {
        return $this->_tokens;
    }

    private function _getConsumerKey()
    {
        return $this->_tokens['consumer_key'];
    }

    private function _getConsumerSecret()
    {
        return $this->_tokens['consumer_secret'];
    }

    public function getAccessKey(){ return $this->_getAccessKey(); }

    private function _getAccessKey()
    {
        $tokens = $this->_obj->session->userdata('twitter_oauth_tokens');
        return ( $tokens === FALSE || !isset($tokens['access_key']) || empty($tokens['access_key']) ) ? NULL : $tokens['access_key'];
    }

    private function _setAccessKey($access_key)
    {
        $tokens = $this->_obj->session->userdata('twitter_oauth_tokens');

        if ( $tokens === FALSE || !is_array($tokens) )
        {
            $tokens = array('access_key' => $access_key);
        }
        else
        {
            $tokens['access_key'] = $access_key;
        }

        $this->_obj->session->set_userdata('twitter_oauth_tokens', $tokens);
    }

    public function getAccessSecret(){ return $this->_getAccessSecret(); }

    private function _getAccessSecret()
    {
        $tokens = $this->_obj->session->userdata('twitter_oauth_tokens');
        return ( $tokens === FALSE || !isset($tokens['access_secret']) || empty($tokens['access_secret']) ) ? NULL : $tokens['access_secret'];
    }

    private function _setAccessSecret($access_secret)
    {
        $tokens = $this->_obj->session->userdata('twitter_oauth_tokens');

        if ( $tokens === FALSE || !is_array($tokens) )
        {
            $tokens = array('access_secret' => $access_secret);
        }
        else
        {
            $tokens['access_secret'] = $access_secret;
        }

        $this->_obj->session->set_userdata('twitter_oauth_tokens', $tokens);
    }

    private function _setAccessTokens($tokens)
    {
        $this->_setAccessKey($tokens['oauth_token']);
        $this->_setAccessSecret($tokens['oauth_token_secret']);
    }

    public function setAccessTokens($tokens)
    {
        return $this->_setAccessTokens($tokens);
    }

    private function _getAuthorizationUrl()
    {
        $token = $this->_getRequestToken();
        return $this->_authorizationUrl.'?oauth_token=' . $token->oauth_token;
    }

    private function _getRequestToken()
    {
        return $this->_httpRequest('GET', $this->_requestTokenUrl);
    }

    private function _getAccessToken()
    {
        return $this->_httpRequest('GET', $this->_accessTokenUrl);
    }

    protected function _httpRequest($method = null, $url = null, $params = null)
    {
        if( empty($method) || empty($url) ) return FALSE;
        if ( empty($params['oauth_signature']) ) $params = $this->_prepareParameters($method, $url, $params);

        $this->_connection = new tweetConnection();

        try {
            switch ( $method )
            {
                case 'GET':
                    return $this->_connection->get($url, $params);
                break;

                case 'POST':
                    return $this->_connection->post($url, $params);
                break;

                case 'PUT':
                    return NULL;
                break;

                case 'DELETE':
                    return NULL;
                break;
            }
        } catch (tweetException $e) {
            $this->_errors[] = $e;
        }
    }

    private function _getCallback()
    {
        return $this->_callback;
    }

    public function setCallback($url)
    {
        $this->_callback = $url;
    }

    private function _prepareParameters($method = NULL, $url = NULL, $params = NULL)
    {
        if ( empty($method) || empty($url) ) return FALSE;

        $callback = $this->_getCallback();

        if ( !empty($callback) )
        {
            $oauth['oauth_callback'] = $callback;
        }

        $this->setCallback(NULL);

        $oauth['oauth_consumer_key']        = $this->_getConsumerKey();
        $oauth['oauth_token']               = $this->_getAccessKey();
        $oauth['oauth_nonce']               = $this->_generateNonce();
        $oauth['oauth_timestamp']           = time();
        $oauth['oauth_signature_method']    = $this->_signatureMethod;
        $oauth['oauth_version']             = $this->_version;

        array_walk($oauth, array($this, '_encode_rfc3986'));

        if ( is_array($params) )
        {
            array_walk($params, array($this, '_encode_rfc3986'));
        }

        $encodedParams = array_merge($oauth, (array)$params);

        ksort($encodedParams);

        $oauth['oauth_signature'] = $this->_encode_rfc3986($this->_generateSignature($method, $url, $encodedParams));
        return array('request' => $params, 'oauth' => $oauth);
    }

    private function _generateNonce()
    {
        return md5(uniqid(rand(), TRUE));
    }

    private function _encode_rfc3986($string)
    {
        return str_replace('+', ' ', str_replace('%7E', '~', rawurlencode(($string))));
    }

    private function _generateSignature($method = null, $url = null, $params = null)
    {
        if( empty($method) || empty($url) ) return FALSE;

        // concatenating
        $concatenatedParams = '';

        foreach ($params as $k => $v)
        {
            $v = $this->_encode_rfc3986($v);
            $concatenatedParams .= "{$k}={$v}&";
        }

        $concatenatedParams = $this->_encode_rfc3986(substr($concatenatedParams, 0, -1));

        // normalize url
        $normalizedUrl = $this->_encode_rfc3986($this->_normalizeUrl($url));
        $method = $this->_encode_rfc3986($method); // don't need this but why not?

        $signatureBaseString = "{$method}&{$normalizedUrl}&{$concatenatedParams}";
        return $this->_signString($signatureBaseString);
    }

    private function _normalizeUrl($url = NULL)
    {
        $urlParts = parse_url($url);

        if ( !isset($urlParts['port']) ) $urlParts['port'] = 80;

        $scheme = strtolower($urlParts['scheme']);
        $host = strtolower($urlParts['host']);
        $port = intval($urlParts['port']);

        $retval = "{$scheme}://{$host}";

        if ( $port > 0 && ( $scheme === 'http' && $port !== 80 ) || ( $scheme === 'https' && $port !== 443 ) )
        {
            $retval .= ":{$port}";
        }

        $retval .= $urlParts['path'];

        if ( !empty($urlParts['query']) )
        {
            $retval .= "?{$urlParts['query']}";
        }

        return $retval;
    }

    private function _signString($string)
    {
        $retval = FALSE;
        switch ( $this->_signatureMethod )
        {
            case 'HMAC-SHA1':
                $key = $this->_encode_rfc3986($this->_getConsumerSecret()) . '&' . $this->_encode_rfc3986($this->_getAccessSecret());
                $retval = base64_encode(hash_hmac('sha1', $string, $key, true));
            break;
        }

        return $retval;
    }

}

@cdevroe
Copy link

cdevroe commented Apr 19, 2011

I thought CodeIgniter, by default, disabled querystring? So, now I have to hack that or simply change my setting? Is there anyway to change the setting just for this one URL?

@cdevroe
Copy link

cdevroe commented Apr 19, 2011

Also, if the above is true, maybe the documentation for the library should say that?

@rayfranco
Copy link
Author

Hi,

I'm not sure at all about the querystring enabling, It's twitter side problem, isn't it? There is nothing from your application side that will tells Twitter if he had registered the loggedin user to your App or not, Actually its only guessing. Are you working from your localhost ? Have you well registered you app with the right callback URL (or setting it manually) ? Have you applied the patch ?

abhaykumar, have you tried the path before enabling the querystring ? It wasn't working ?

Cheers

Envoyé de mon iPhone

Le 19 avr. 2011 à 22:43, [email protected] a écrit :

Also, if the above is true, maybe the documentation for the library should say that?

Reply to this email directly or view it on GitHub:
#2 (comment)

@hackmyway
Copy link

Hi,

RayFranco yes i tried the path before enabling the querystring. It wasn't working for me.

In the constructor of tweet_test controller i had to do this:

$qs = $_SERVER['QUERY_STRING'];
$ru = $_SERVER['REQUEST_URI'];
$pp = substr($ru, strlen($qs)+1);
parse_str($pp, $_GET);

checkout:
www.jobiance.com/tweet_test for live example.

@rayfranco
Copy link
Author

Hi,

I've checked my project where I've build this patch to make it working, I didn't do this little hack you did (I had to use it one day but on a different case). Here are what I've changed from the config.php about url's :

$config['uri_protocol'] = 'REQUEST_URI';
$config['permitted_uri_chars'] = 'a-z 0-9~%.\:\_\-\+\=';

Here I'm still on Query String disabled :

$config['enable_query_strings'] = FALSE;

This makes it working enough for me. I still didn't catch where it makes a difference.... Strange thing.

@cdevroe
Copy link

cdevroe commented Apr 21, 2011

@rayfranco or anyone else. Can someone provide me with their Tweet_test controller? I think I've narrowed down my problem to the fact that no matter what, this line is always TRUE

if ( !$this->tweet->logged_in() )

@rayfranco
Copy link
Author

Hi cdevroe,

I'm not testing on that Tweet_test controller that provides the lib, it seems to be a little intrusive so I just use it as a "snippet" to quicky see what are the methods that suit my needs.

In practice, I do not check if the user is connected to the app on every controller call. When the user is loggin-in, I check if he is in my database, if not, insert the infos I need, if so, just update the infos then I use these until the end of the session. It's a bit more conventional I think...

Here is my login method I use in my last twitter app :

public function login()
{

    $this->load->model('User_model', 'User');

    if ( ! $this->tweet->logged_in() )
    {
        if ( $this->uri->rsegment(3) ) {
            $this->session->set_userdata('callback_url',base64_decode($this->uri->rsegment(3)));
        }
        $this->tweet->set_callback(site_url('home/login'));
        $this->tweet->login();
        die();
    }
    else
    {
        $this->user = $this->tweet->call('get', 'account/verify_credentials');

        if ( ! $user = $this->User->exists((string)$this->user->id) )
        {
            $user = $this->User->create($this->user, $this->tweet->get_tokens());
            $this->User->hook_points('create_account',$user);
            $this->flash->add('Bienvenue sur XXXXXX !','valid');
        }
        else
        {
            $this->User->hook_points('connexion',$user);
            $this->flash->add('Vous nous aviez manqué !','valid');
        }
        $this->session->set_userdata('user',serialize($this->User->get($user)));

        if ( $this->session->userdata('callback_url') )
        {
            redirect( $this->session->userdata('callback_url') );
        }
        else
        {
            redirect('home/index');
        }
    }
}

The third segment is used to redirect the user to the page he checked the logged in user. It's not very sexy tho ;)

Hope this helps.

@cdevroe
Copy link

cdevroe commented Apr 21, 2011

@rayfranco First, thanks to you and everyone else for helping me out with this issue. Beer is on me shall we ever meet.

Second, I see what you're doing here only $this->tweet->get_tokens() (for me) doesn't seem to get the tokens returned from Twitter. And I'm not sure why.

Also, if I look at your tweet.php library and @abhaykumar 's tweet.php library you two are using two different URLs. Authenticate vs. Authorize. I'm using Authenticate (as it appears that you are).

@cdevroe
Copy link

cdevroe commented Apr 21, 2011

@rayfranco & @abhaykumar I've shared my tweet_test controller here: https://gist.github.com/f5bc3f0b18b66bdf61ee

@rayfranco
Copy link
Author

@cdevroe Can you tell me what

$this->tweet->call('get', 'account/verify_credentials');

throws when you got back from login ? Does it says something ?

And are you working on your localhost ? Have you checked the configuration on twitter ? (domain, callback url)
Is the callback url working properly ?

The tokens are useless unless you need to fake a user connection (to send tweets when he's logged out for example). I'm not using them, I just store them, just in case.
The credentials will tell you if the user is logged in or not.

Cheers.

@cdevroe
Copy link

cdevroe commented Apr 21, 2011

@rayfranco The callback works as it runs Auth() on its way back. But nothing from verify_credentials ever makes it because it runs login() again and redirects back to Twitter. Endless loop.

Here is the log file (if you compare it with the Gist)

53 DEBUG - 2011-04-21 14:46:08 --> Language file loaded: language/english/unit_test_lang.php
54 INFO - 2011-04-21 14:46:08 --> Not logged in.
55 INFO - 2011-04-21 14:46:09 --> The user has been sent to Twitter.
56 INFO - 2011-04-21 14:46:09 --> Auth() Tokens were attempted to be retrieved.
57 INFO - 2011-04-21 14:46:09 --> Auth() Tried to verify credentials.
58 INFO - 2011-04-21 14:46:09 --> Auth() Tried to print timeline.
59 DEBUG - 2011-04-21 14:46:09 --> Final output sent to browser
60 DEBUG - 2011-04-21 14:46:09 --> Total execution time: 0.6450

@cdevroe
Copy link

cdevroe commented Apr 22, 2011

Yes, I'm still poking at this. One thing I did notice is that the Library looks for oauth_token and oauth_token_secret and not oauth_verifier (which is what Twitter sends back regardless of the URL /authorize/ or /authenticate/). I think this is my entire issue and now I'm wondering why no one else has run into this.

@cdevroe
Copy link

cdevroe commented Apr 22, 2011

Also, so far I still have yet to enable querystring URLs. When I do $_GET['oauth_token'](which the Library does) I can not retrieve that value. But setting that to TRUE would adversely affect my entire application.

@cdevroe
Copy link

cdevroe commented Apr 22, 2011

@abhaykumar Even your hack for getting the querystring wouldn't work unless I enabled the querystring in CodeIgniter. By default CI disables $_SERVER['QUERY_STRING']

So now I'm left with two issues, as I see them. 1) I can not use $_GET at all and the Library uses that to retrieve the oauth_token. 2) Even if I could use $_GET the Library is looking for oauth_token and oauth_token_secret and Twitter replies with oauth_token and oauth_verifier

Any help here would be great. I consider all of you my idols that any of you ever got this Library working. Who is up for starting a new project where we write our own and support it?

@cdevroe
Copy link

cdevroe commented Apr 22, 2011

After hacking the tweet_test some where to force $_GET I'm hitting a secondary wall. The Library now recognizes as being "logged in" properly. However, it can not gain an Access_Token and Access_Secret, presumably because it would also use $_GET to do this.

The error I get in my logs now is: "Request token must be exchanged for an access token before use". And from what I can see the controller is trying to retrieve this information itself via getAccessKey and getAccessSecret.

I've updated the Gist of my tweet_test controller to show the hack (which I poorly coded since I hope I don't have to actually use it). https://gist.github.com/f5bc3f0b18b66bdf61ee

@carolinecblaker
Copy link

Hi!
Thanks for this contribution, @cdevroe.

Regarding the Request token hoopla, here is an interesting thread to determine if you have tokens:

http://codeigniter.com/forums/viewthread/181901/

If they're saving, $_GET shouldn't be the issue, right?

Turns out mine are available - there's just some kind of weird thing about passing it to Twitter.
Also, I had to change my API key, according to the Twitter oauth api:

    private $_apiUrl            = 'http://api.twitter.com/1';

Baby steps..

@carolinecblaker
Copy link

#6

Check it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants