Haughin’s Twitter Library - Accessing the current user's username. |
[eluser]clayko[/eluser]
Hey Everyone, I'm a relative noob at codeigniter, but I have made some significant progress over the past 6 months. I'm now facing a seemingly simple problem compared to the other problems I have solved while learning the twitter API. I cannot figure out how to access the user's username with Haughin's oAuth twitter API. If anyone could help, I would be very appreciative. Thanks a lot, Clay
[eluser]sheellli[/eluser]
Hi everyone , Even i m stucked in this twitter Api implementation. While a user coming back from twitter, The user_id is lost.which i have stored in an session. Please guide me how to get it.
[eluser]luisfmgoncalves[/eluser]
Hey, I'm not sure if I will anwser the right question, but I hope so... For me is like, after a user login, I store his twitter id in the session. So, when I need to get the use information from twitter I just do: Code: $id = $this->session->userdata('id'); With this, I have the JSON information in $user_info variable. After that, to retrieve the information I just do: Code: if($user_info != NULL){ So, in $data you will have the name, url, location and description of a user (you can retrieve more information, just look at the JSON file structure here: http://apiwiki.twitter.com/Twitter-REST-...hod:-users show) in the end, you just need: Code: echo json_encode($data); or Code: $this->load->view('some_view', $data); Is this what you want? Luis Gonçalves
[eluser]clayko[/eluser]
Hey Luis, This is a HUGE help... I only have one question. First: How do you store his id in the first place? Currently, the code only stores the oauth access tokens. Thanks a lot, Clay
[eluser]luisfmgoncalves[/eluser]
Just a small trick... If you notice, your access_token have the form: id-code, so where you save the access_token and access_token_secret I have the following code: //save user ID in the session Code: list($id, $code) = explode("-", $auth['access_token']); And there it is! Anytime you want to use the id, just do: Code: $id = $this->session->userdata('id'); **Edit** Anyway, I think you can use the method: Code: $user_info = $this->twitter->call('users/show', array('id' => $id)); **Edit** Helps? Luis Gonçalves
[eluser]clayko[/eluser]
Hey again... I feel like I'm on the verge of a breakthrough thanks to you... Unfortunately, I can't get the code to work. Below is (part) of the twitter code... I get the error: "Undefined property: stdClass::$name" when I try to load a view. I assume I'm making a simple mistake... do you know what it is? Thanks a ton, Clay Code: $this->load->library('session');
[eluser]luisfmgoncalves[/eluser]
Maybe you are using the name property in a wrong way... If you have: Code: $data['name'] = $user_info->name; in your view you will acees the name property like: Code: <span><?php echo $screen_name; ?></span> You are using like this? Another question... You afected this 2 variables: Code: $tokens['access_token'] = NULL; With the values that you have when you register the application, right? Luis Gonçalves
[eluser]clayko[/eluser]
I was just trying to echo the $data['name'] from within the controller... When I try to echo $screen_name from the view I get another unknown variable error. Will you take a look at my code for me? I think there's something wrong with the getting of the ID in the first place. I really appreciate all your help. EDIT: Regarding your token question, yes, I have the correct token info from the twitter oauth registration. Thanks again, Clay
[eluser]clayko[/eluser]
My controller code (most of it... not the code to load the view, etc) Code: $consumer_key = 'MY KEY'; THE ERROR: Code: Message: Undefined property: stdClass::$name Line 224: $data['name'] = $user_info->name; |
Welcome Guest, Not a member yet? Register Sign In |