Welcome Guest, Not a member yet? Register   Sign In
MeNeedz Twitter
#21

[eluser]BobbyB[/eluser]
Ok,
I kind of got it working now.
Code:
function statuses_user_timeline($user_id = FALSE)
    {
      //Added this  
        $patterns = array(
            // Detect URL's
            '|([a-z]{3,9}://[a-z0-9-_./?&+]*)|i' => '<a href="$0" target="_blank">$0</a>',
            
            // Detect Email
            '|[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,6}|i' => '<a href="mailto:$0">$0</a>',
            
            // Detect Twitter @usernames
            '|@([a-z0-9-_]+)|i' => '<a href="http://twitter.com/$1" target="_blank">$0</a>',
            
            // Detect Twitter #tags
            '|#([a-z0-9-_]+)|i' => '<a href="http://twitter.com/search?q=#$1" target="_blank">$0</a>'
        );
/////////////////
        
        $post_values = array();
        if($user_id !== FALSE)
        {
            $post_values['id'] = $user_id;
        }

        $result = $this->request('GET', 'statuses/user_timeline', TRUE, $post_values);
        
        if(is_array($result))
        {
        //I changed/added this section    
            foreach($result[1] as $tweet){
            $return[] = array(    
            'text' => preg_replace(array_keys($patterns), array_values($patterns), $tweet['text']),
            'created_at' => $tweet['created_at'],
            'profile_image_url' => $tweet['user']['profile_image_url']
            
            );
            }
            return $return;
//
        }
        else
        {
            return FALSE;
        }        
    }
Code:
return array($response[0], json_decode($response[1],true));//In the "parse_response" function I added true
Its probably terrible code and unefficient but it works so far.
Maybe somebody knows a better way.
#22

[eluser]BobbyB[/eluser]
Hi Waldmeister,
I got another question for you:
I am trying to get the latest tweets from a user like this:
Code:
$this->load->library('twitter');
$config['username'] = 'myusername';
$config['password'] = 'mypassword';
$this->twitter->init($config);
$data['tweets'] = $this->twitter->statuses_user_timeline('bob');
But it does not work. It just loads forever.
Using:
Code:
...
$data['tweets'] = $this->twitter->statuses_user_timeline();
works great. Any hints?
Thanks in advance!
#23

[eluser]davidbehler[/eluser]
$this->twitter->statuses_user_timeline() expects the user_id as parameter. Right now it's not possible to get the latest tweets by passing the actual username.

Try this quick update to the library:

Code:
function statuses_user_timeline($values = FALSE)
    {
        $post_values = array();
        if($values !== FALSE)
        {
            if(is_array($values)) {
                $post_values = $values;
            } else {
                $post_values['id'] = $values;
            }
        }

        $result = $this->request('GET', 'statuses/user_timeline', TRUE, $post_values);

        if(is_array($result))
        {
            return $result[1];
        }
        else
        {
            return FALSE;
        }
    }
Now you can either pass the user_id (as before) or pass an array of key => value pairs you want to pass as parameter when accessing the twitter api.

In your case you could try this:
Code:
$this->twitter->statuses_user_timeline(array('screen_name' => 'bob'));
#24

[eluser]BobbyB[/eluser]
Hi,
thanks for the quick reply.
Turns out it does actually work, but it just takes forever(3-5 minutes).
Same with the updated script.
This guy here seems to have the same problem with a script very similar:
link
An alternative using curl would be great Smile)

Best regards
#25

[eluser]davidbehler[/eluser]
There are plenty of cURL Twitter libraries out there...I just don't like using them as my webhoster does not support cURL and that means I have to use fsockopen and so on.
#26

[eluser]BobbyB[/eluser]
Oh I see,
but does the script work for you?
I don't get why it works great without parameters
but it doesn't when I pass parameters.
Strange...
#27

[eluser]takasia[/eluser]
Hi there!
I really thank you for a great library - got it working and posting in no time. :-)

I have a question - don't know much about codeigniter and all - but I want to get some of the user data - like location.

How can I do that?

What I want to do is: someone logs in with his twitter login and password, and gets a google map with the people he follows as markers with their last tweet in the marker bubble.

For this I need their [location] parameter and their tweet [text]
- but how to obtain them?

It's not for any project - I'm just trying to learn and setting myself some goals :-)
#28

[eluser]davidbehler[/eluser]
I'm not sure this can be done easily, but if you have a look at the Twitter API you might find something:

statuses-friends-timeline and [url=http://apiwiki.twitter.com/Twitter-REST-API-Method:-statuses-home_timeline]statuses-home-timeline] return a list of the last 20-200 statuses of your friends (the later includes retweets). For each friend you either get the geo info or not...depending on wether they have that feature enabled or not.

I haven't looked into this library for a while but it shouldn't be to complicated and ca be expanded easily.
#29

[eluser]takasia[/eluser]
Thank you thank you thank you! :-)

I added this to your library:
function statuses_friends_timeline($user_id = FALSE)
{
$post_values = array();
if($user_id !== FALSE)
{
$post_values['id'] = $user_id;
}

$result = $this->request('GET', 'statuses/friends_timeline', TRUE, $post_values);

if(is_array($result))
{
return $result[1];
}
else
{
return FALSE;
}
}

then did this:
$timeline = $this->twitter->statuses_friends_timeline();

and got what I wanted :-) I mean - I can extract from the timeline whatever I need :-)

I wanted to try to give the location info krom the timeline to GoogleMaps API and show it on the map BUT.... one problem.... the GEO function in Twitter is for now aviable only in US! :-(

I live in Japan so... :down:

Thank you anyway :-D
--
Kasia
Twitter:
@kasia
@joomla_cms_info
#30

[eluser]Naveen Reddy[/eluser]
Hi,
Thanks for the twitter library.
I would like to know, How can we use this library to access the number of followers and the list of followers into our site.

thanks




Theme © iAndrew 2016 - Forum software by © MyBB