Welcome Guest, Not a member yet? Register   Sign In
Haughin’s Twitter Library - Accessing the current user's username.
#11

[eluser]luisfmgoncalves[/eluser]
Ok... Here is my code:

Code:
//function to do the authentication
function twitter_exp() {

    $consumer_key = 'KEY';
    $consumer_key_secret = 'KEY_SECRET';

    $tokens['access_token'] = NULL;
    $tokens['access_token_secret'] = NULL;

    // GET THE ACCESS TOKENS
    $oauth_tokens = $this->session->userdata('twitter_oauth_tokens');

    if ( $oauth_tokens != FALSE ) $tokens = $oauth_tokens;
        
    $auth = $this->twitter->oauth($consumer_key, $consumer_key_secret, $tokens['access_token'], $tokens['access_token_secret']);

    if ( isset($auth['access_token']) && isset($auth['access_token_secret']) ) {

        // SAVE THE ACCESS TOKENS
        $this->session->set_userdata('twitter_oauth_tokens', $auth);

        $this->session->set_userdata('access_token', $auth['access_token']);
        $this->session->set_userdata('access_token_secret', $auth['access_token_secret']);

        //save user ID in the session
        list($id, $code) = explode("-",  $auth['access_token']);
        $this->session->set_userdata('id', $id);

        //$this->session->set_userdata('logged_in', TRUE);
        $this->session->set_userdata('logged_in', TRUE);

        if ( isset($_GET['oauth_token']) ) {
            $uri = $_SERVER['REQUEST_URI'];
            $parts = explode('?', $uri);

            // Now we redirect the user since we've saved their stuff!
            header('Location: '.$parts[0]);

            return;
        }
    }
}


Code:
//to get the user info
function get_user_info(){

    $this->twitter_exp();

    $id = $this->session->userdata('id');

    $user_info = $this->twitter->call('users/show', array('id' => $id));
    
    $data["name"] = $user_info->name;
    $data["description"] = $user_info->description;
    $data["location"] = $user_info->location;
    $data["url"] = $user_info->url;

    $this->load->view('some_view', $data);
}

So, if you have this code, your Callback URL in twitter application should have the following url:

http://domain/project/controller/get_user_info

This is working for me... and this is not so hard to undersrtand. I rather want to give you my code than check yours. Sorry, but I dont like to do that (in my work is enought).

Hope it helps

Luis Gonçalves


Messages In This Thread
Haughin’s Twitter Library - Accessing the current user's username. - by El Forum - 05-26-2010, 05:37 AM



Theme © iAndrew 2016 - Forum software by © MyBB