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
#12

[eluser]clayko[/eluser]
Thank you so much, Luis! This has helped me IMMENSELY!

I will try out this code and let you know how it works... This is a major breakthrough for me!

Thanks again,
Clay
#13

[eluser]clayko[/eluser]
I hate to be a bother, but I can't get this to work.... I'll keep trying but I don't know what the problem is!

- Clay
#14

[eluser]clayko[/eluser]
It's working! It's working!

I really can't thank you enough, Luis!

!!!,
Clay
#15

[eluser]umefarooq[/eluser]
hi really nice to see that you have configured it but i have very hard luck with this library can you help me how to solve this problem, i just check with oauth i have to send some callback but if im using localhost server how can i set callback server for it or i have to host my application on some server to test it. well i have tried on localhost every time im redirected to this twitter page

http://twitter.com/oauth/authorize?oauth_token=
#16

[eluser]luisfmgoncalves[/eluser]
@clayko: Congrats.

@umefarooq: I'm working localhost too, but I have it working...
What you can do is, in you hosts file (present in C:\Windows\System32\drivers\etc), you can put an entry pointing the callback url to a specific IP. So, if your project domein is www.example.com, you just need to add the following line to your hosts file:

Code:
127.0.0.1                example.com

I managed the thing with this...

Hope it helps.

Luis Gonçalves
#17

[eluser]alboyd[/eluser]
This thing is making me bald! I have no idea why this isn't working but this is what is happening..

Taking the example controller functions that the most recent guy posted I go to the twitter_exp function and i get sent off to Twitter for auth.

I say ALLOW.

I go into the redirect thing and then I come back again and it is asking if I want to Allow again...

This just repeats..

Things I have done:
I have left uri_protocal = AUTO because when I change to PATH_INFO I can't access any page except my main default route.

I have changed the permitted_uri_chars to include the ?

I have enabled query strings.

Anyone got a clue cause I certainly don't and I've wasted about 2 hours on this tonight! arrgghh!!!!! Thanks! Smile
#18

[eluser]luisfmgoncalves[/eluser]
Hey...

After some time using Haughin library, I re-wrote my application with Abrahan library... Is more complete.

But talking about your problem, I think the problem is in your .htaccess file.
Can you put the content of that file here?
Put the content of your config.php file too, please.

Luis




Theme © iAndrew 2016 - Forum software by © MyBB