My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
ExampleCode  
Updated Feb 4, 2010 by emmenset...@gmail.com

Code Samples

Check to see if Twitter is available

$t = new twitter();
$t->username='myuser';		
$t->password='mypass';
echo'<pre>';
print_r( $t->ratelimit() );
echo'</pre>';

Returns

stdClass Object
(
    [remaining_hits] => 30
)

Get the Public Timeline

$t = new twitter();
$t->username='myuser';		
$t->password='mypass';
$t->type='xml';
echo'<pre>';
print_r( $t->publicTimeline() );
echo'</pre>';

Returns (shortened for brevity)

stdClass Object
(
    [0] => SimpleXMLElement Object
        (
            [created_at] => Thu May 29 05:24:38 +0000 2008
            [id] => 822268611
            [text] => GeoTwittering. http://geotwitter.net/l.aspx?g=78
            [source] => GeoTwitter.Net
            [truncated] => false
            [in_reply_to_status_id] => SimpleXMLElement Object
                (
                )

            [in_reply_to_user_id] => SimpleXMLElement Object
                (
                )

            [favorited] => false
            [user] => SimpleXMLElement Object
                (
                    [id] => 736393
                    [name] => Derik Olsson
                    [screen_name] => derik
                    [location] => Flower Mound, Texas
                    [description] => Entrepreneur in the video & web fields.
                    [profile_image_url] => http://s3.amazonaws.com/twitter_production/profile_images/53445703/hb_sm_normal.jpg
                    [url] => http://derikolsson.com
                    [protected] => false
                    [followers_count] => 12
                )

        )

    [1] => SimpleXMLElement Object
        (
            [created_at] => Thu May 29 05:24:54 +0000 2008
            [id] => 822268609
            [text] => @miki7500 まだ食べ終わってなかったのか
            [source] => web
            [truncated] => false
            [in_reply_to_status_id] => 822268441
            [in_reply_to_user_id] => 6098852
            [favorited] => false
            [user] => SimpleXMLElement Object
                (
                    [id] => 12902532
                    [name] => ALeE/ありーくっく
                    [screen_name] => ALeE78
                    [location] => Japan,hyogo
                    [description] => ♂。えいりと呼ぶ人もいます。格ゲー部、メガネ美人部、diablo部、モンハン部。モンハン日記→http://monsterhunter.g.hatena.ne.jp/alee/
                    [profile_image_url] => http://s3.amazonaws.com/twitter_production/profile_images/54304388/cook_normal.jpg
                    [url] => http://iddy.jp/profile/alee78/
                    [protected] => false
                    [followers_count] => 464
                )

        )
Comment by neclay...@gmail.com, Mar 23, 2009

Not having any luck with either the updateColors or updateBackground methods. Passing an array with the proper data for updateColors and a binary image for updateBackground. Are these methods functioning properly or am I missing something?

Could you provide examples of them in action please? I would really appreciate it.

Comment by india...@gmail.com, May 9, 2009

thanks ver y good work

Comment by radicalx...@gmail.com, Jun 6, 2009

cool i hope it work

Comment by radicalx...@gmail.com, Jun 22, 2009

it did work but during update it will not work

Comment by vinodkum...@gmail.com, Jul 22, 2009

How to find out the username and password is correct?

Comment by tuvinhvi...@gmail.com, Jul 29, 2009

@vinodkumark87 I think it is not hard to check Twitter account. Following are 2 ways and I think they work well:

//1. Get public time line with your username and password: $oTwit = new twitter(); $oTwit->username = 'folext'; $oTwit->password = 'folext'; $oTwit->type = 'xml'; $aPublicUpdates = $oTwit->publicTimeline(); if(count($aPublicUpdates) > 0){

echo "Done";
}else{
echo "Error";
} /////////////// //2. Send a test update and remove it immediately.

Comment by leadbett...@gmail.com, Aug 20, 2009

Where do I put this file if I want it to work on a wordpress page?

Comment by mfratto, Aug 24, 2009

If you are trying to get tweets using the since_id parameter, bear in mind that your results may not be correct. It seems that when PHP encounters an INT that is larger than PHP_INT_MAX, it will convert it to a float. That SHOULD be OK, but I found that, at least with PHP 5.2.9, when an INT larger than PHP_INT_MAX was wrapped to a negative number. A simple fix was to go into the method that I was calling and change the variable type cast from INT to FLOAT.

For example, on my system, the following code: echo "My big number is: 3523044696\n"; echo "On my system PHP 5.2.9, PHP_INT_MAX size is " . PHP_INT_MAX . "\n"; $x = (int)3523044696; echo "Stuffed into an integer, my number becomes $x\n";

yields:

My big number is: 3523044696 On my system PHP 5.2.9, PHP_INT_MAX size is 2147483647 Stuffed into an integer, my number becomes -771922600

Comment by satya61...@gmail.com, Oct 13, 2009

Someone who try the first example will find this code not working. Try second one. In first one. there is an error in function ratelimit(). Change from this: return $this->objectify( $out ); To: return $this->objectify( $this->process($out) );

Comment by dushyant...@gmail.com, Mar 24, 2010

The first and second examples are not working....I tried step 1 of tuvinhvietnam and it works...What can be the problem?

Comment by dejan.jo...@gmail.com, Feb 13, 2011

this stuff seems to be deprecated, twitter doesn't support basic auth anymore


Sign in to add a comment
Powered by Google Project Hosting