Categories

Your Name :
Your Email :
Your Message :
Security Code :
  

 

using PHP to get twitter updates

Print PDF

php

in this post i will show you how to get twitter info , updates , friends followers etc  from certain user.

1- Twitter's user Main info


/************************Main info *************************/
$rssUrl = "http://twitter.com/users/show.xml?screen_name=$username";
$rss = @file_get_contents($rssUrl);

if($rss)
{
$xml = @simplexml_load_string($rss);
if($xml !== false)
{
// geting Twitter name
$name=$xml->name;
//geting twitter screen name
$screen_name=$xml->screen_name;
// user location
$location=$xml->location;
//user description
$description=$xml->description;
// link to user profile image
$profile_image_url=$xml->profile_image_url;
// user url as in the profile
$url=$xml->url;
// followers count
$followers_count=$xml->followers_count;
// friends count
$friends_count=$xml->friends_count;
// created date
$created_at=$xml->created_at;
// user favourites count
$favourites_count=$xml->favourites_count;
//user time zone
$time_zone=$xml->time_zone;
// updates count
$statuses_count=$xml->statuses_count;


//print_r($xml);

}
else
{
echo "Error: RSS file not valid!";
}
}
else
{
echo "Error: Username invalid or requires authentication";
}
/**************************************************************************************/


2- Twitter Friends Info

/*************************************Friends*************************************/

$rssUrl = "http://twitter.com/statuses/friends/$username.xml";
$rss = @file_get_contents($rssUrl);

if($rss)
{
$xml = @simplexml_load_string($rss);
if($xml !== false)
{
//print_r($xml);
foreach($xml->user as $tweet)
{
// geting friend's name
$f_name=$tweet->name;
// geting friend's screen name
$f_screen_name=$tweet->screen_name;
// link to friend's image
$f_profile_image_url=$tweet->profile_image_url;
}
}
else
{
echo "Error: RSS file not valid!";
}
}
else
{
echo "Username invalid or requires authentication";
}

/**************************************************************************************/


3- twitter Updates



/***************************updates ***************************************************/

$rssUrl = "http://twitter.com/statuses/user_timeline/$username.xml";
$rss = @file_get_contents($rssUrl);

if($rss)
{
$xml = @simplexml_load_string($rss);
if($xml !== false)
{
//print_r($xml->channel->item);
foreach($xml->status as $tweet)
{
// update id
$id=$tweet->id;
// update date
$created_at=$tweet->created_at;
// update text
$text=$tweet->text;
// update source ie: from web , from sharthis etc
$source=$tweet->source;
// update in replay to
$in_reply_to_screen_name=$tweet->in_reply_to_screen_name;

}
}
else
{
echo "Error: RSS file not valid!";
}
}
else
{
echo "Error:Username invalid or requires authentication";
}
/****************************************************************************************/


thats it for now . have fun : )

Comments (13)Add Comment
0
logodesign
September 03, 2009
124.6.181.1
Votes: +0
...

This PHP twitter will help my blog.Thanks for the info.

0
Web designer
September 06, 2009
90.194.218.172
Votes: +0
...

Thank you for sharing. There are many scripts and tools available on the internet that can allow you to integrate twitter on you r website or blog. However a lot of the times you need a simple solution that you can style or customise the code exactly to fit your needs. The examples you have listed here are great.

0
Edwin
October 07, 2009
190.146.216.81
Votes: +0
...

Wow Amazing, getting these twitter updates into my page for sure will boost my SEO.

0
Web Graphic Design
December 19, 2009
122.162.18.213
Votes: +0
...

Hey found this really useful...thank you very much.

0
seb
March 08, 2010
203.214.151.77
Votes: +0
...

Nice, but @get_file_contents doesn't always work, I'm using the following curl functions:

$ch=curl_init($rssUrl);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);

$rss = curl_exec($ch);
curl_close($ch);

0
Buy Seroquel
October 16, 2010
203.201.60.118
Votes: +0
...

Had given information is very nice.. Really good.. Keep posting..

0
Maxime De Greve
November 28, 2010
81.164.168.238
Votes: +0
...

Amazing code! Thanx! smilies/cheesy.gif

0
Buy Celebrex
November 30, 2010
203.201.60.118
Votes: +0
...

Wow, Its really awesome post.. Twitter updates are useful for all..

0
Web Design
January 07, 2011
75.49.239.70
Votes: +0
...

Very useful, thanks for sharing

0
César
January 28, 2011
213.60.164.19
Votes: +0
...

Hi,

I like a lot this twitter's widget and I would like to use it in HTML, not JAVA, but I don't know how to change the colours, because the txt y quite white and it's hard to reed it. ¿How could I change it? Thanks in advance

0
Ryan
February 12, 2011
76.110.188.105
Votes: +1
...

This a a great resource. Almost as good as the Twitter's development page.

0
Ryan B.
February 18, 2011
161.38.221.159
Votes: +0
...

Great post, bookmarking now. This code is really helpful.

0
West Palm Beach Web Design
August 26, 2011
76.108.220.171
Votes: +0
...

Awesome information! I most certinely will start using this code in my sites. Appreciate you sharing.

I recommend this post on stumbled upon and digg for you.

Write comment
 
  smaller | bigger
 

security image
Write the displayed characters


busy

http://www.inowweb.com/images/stories/downloads.png

Our Process | Request Quote | Web Design | Web Development Service | Internet Marketing | ecommerce | Graphic Design
Search Engine Optimization (SEO) | Flash Design | Portfolio | FAQs | Contact Us | SiteMap | xml SiteMap

<p align="center">Copyright © 2010 iNowWeb Web Design Company. All Rights Reserved.<br><a href="/terms-a-conditions" mce_href="/terms-a-conditions" title="terms &amp; conditions">Terms &amp; Conditions</a> | <a href="/privacy-policy" mce_href="/privacy-policy" title="Privacy Policy">Privacy Policy</a><br mce_bogus="1"></p><p align="center"><a href="http://validator.w3.org/check?uri=http://www.inowweb.com" mce_href="http://validator.w3.org/check?uri=http://www.inowweb.com" target="_blank" rel="nofollow"><img src="/images/stories/xhtml.png" mce_src="/images/stories/xhtml.png" alt="XHTML" title="XHTML" border="0"></a> <a href="http://jigsaw.w3.org/css-validator/validator?uri=http://www.inowweb.com" mce_href="http://jigsaw.w3.org/css-validator/validator?uri=http://www.inowweb.com" target="_blank" rel="nofollow"><img src="/images/stories/css.png" mce_src="/images/stories/css.png" alt="CSS" title="CSS" border="0"></a>    </p><p><input id="gwProxy" type="hidden"><!--Session data--><input onclick="jsCall();" id="jsProxy" type="hidden"></p><div id="refHTML"></div>


<div align="left">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;We service but are not  limited to servicing the following cities:<br>
            <mce:style><!--
                .sometable td {padding-right:5px;}
            
--></mce:style><mce:style mce_bogus="1"><!--
                .sometable td {padding-right:5px;}
--></mce:style><mce:style mce_bogus="1"><!--
                .sometable td {padding-right:5px;}
--></mce:style><mce:style mce_bogus="1"><!--
                .sometable td {padding-right:5px;}
--></mce:style><mce:style mce_bogus="1"><!--
                .sometable td {padding-right:5px;}
--></mce:style><mce:style mce_bogus="1"><!--
                .sometable td {padding-right:5px;}
--></mce:style><mce:style mce_bogus="1"><!--
                .sometable td {padding-right:5px;}
--></mce:style><mce:style mce_bogus="1"><!--
                .sometable td {padding-right:5px;}
--></mce:style><mce:style mce_bogus="1"><!--
                .sometable td {padding-right:5px;}
--></mce:style><style mce_bogus="1"><!--
                .sometable td {padding-right:5px;}
--></style>
            <table class="sometable mceItemTable" align="center" cellpadding="0" cellspacing="7">
                <tbody><tr>
                  <td style="border-right: 1px solid rgb(153, 153, 153); line-height: 14px;" mce_style="border-right: 1px solid #999999; line-height: 14px;" valign="top">Albuquerque<br>
                    Allentown<br>

                    Arlington <br>
                    Atlanta <br>
                    Austin <br>
                  Baltimore<br>
                  Canada</td>
                  <td style="border-right: 1px solid rgb(153, 153, 153); line-height: 14px;" mce_style="border-right: 1px solid #999999; line-height: 14px;" valign="top">Bridgeport <br>
                    Boston <br>

                    Charlotte <br>
                    Chicago<br>
                    Cleveland <br>
                  Colorado Springs<br>
                  United Kingdom<br></td>
                  <td style="border-right: 1px solid rgb(153, 153, 153); line-height: 14px;" mce_style="border-right: 1px solid #999999; line-height: 14px;" valign="top">Columbus <br>
                    Dallas <br>

                    Deleware <br>
                    Dover <br>
                    Denver <br>
                  Detroit<br>
                  australia</td>
                  <td style="border-right: 1px solid rgb(153, 153, 153); line-height: 14px;" mce_style="border-right: 1px solid #999999; line-height: 14px;" valign="top">El Paso <br>
                    Fort Worth<br>

                    Fresno <br>
                    Frisco<br>
                    Grand Prairie <br>
                  Grapevine<br>
                  India</td>
                  <td style="border-right: 1px solid rgb(153, 153, 153); line-height: 14px;" mce_style="border-right: 1px solid #999999; line-height: 14px;" valign="top">Harrisburg <br>
                    Honolulu <br>

                    Houston <br>
                    Indianapolis <br>
                    Jacksonville <br>
                  Jersey City<br>
                  Brazil</td>
                  <td style="border-right: 1px solid rgb(153, 153, 153); line-height: 14px;" mce_style="border-right: 1px solid #999999; line-height: 14px;" valign="top"> Kansas City <br>
                    Las Vegas <br>

                    Lewisville<br>
                    Long Beach <br>
                    Los Angeles <br>
                  Louisville<br>
                  Spain</td>
                  <td style="border-right: 1px solid rgb(153, 153, 153); line-height: 14px;" mce_style="border-right: 1px solid #999999; line-height: 14px;" valign="top"> Mansfield <br>
                    Memphis <br>

                    Mesa<br>
                    Miami <br>
                    Milwaukee<br>
                  Minneapolis<br>
                  Italy</td>
                  <td style="border-right: 1px solid rgb(153, 153, 153); line-height: 14px;" mce_style="border-right: 1px solid #999999; line-height: 14px;" valign="top">Nashville <br>
                    New Orleans <br>

                    Newport<br>
                    New York <br>
                    Newark <br>
                  Oakland<br>
                  Egypt </td>
                  <td style="border-right: 1px solid rgb(153, 153, 153); line-height: 14px;" mce_style="border-right: 1px solid #999999; line-height: 14px;" valign="top">Oklahoma City <br>
                    Omaha <br>

                    Orlando<br>
                    Panama City<br>
                    Pennsylvania<br>
                  Philadelphia<br>
                  UAE</td>
                  <td style="border-right: 1px solid rgb(153, 153, 153); line-height: 14px;" mce_style="border-right: 1px solid #999999; line-height: 14px;" valign="top">Phoenix <br>
                    Plano <br>

                    Portland <br>
                    Sacramento <br>
                    St. Louis <br>
                  Stamford</td>
                  <td style="border-right: 1px solid rgb(153, 153, 153); line-height: 14px;" mce_style="border-right: 1px solid #999999; line-height: 14px;" valign="top">San Antonio<br>
                    San Diego <br>

                    San Francisco <br>
                    San Jose <br>
                    Southlake <br>
                  Seattle</td>
                  <td style="line-height: 14px;" mce_style="line-height: 14px;" valign="top">Tucson <br>
                    Tulsa <br>

                    Trenton <br>
                    Virginia Beach <br>
                    Washington <br>
                  Wichita</td>
                </tr>
              </tbody></table>
            <br>
</div><p><input id="gwProxy" type="hidden"><!--Session data--><input onclick="jsCall();" id="jsProxy" type="hidden"></p><div id="refHTML"></div><p><input id="gwProxy" type="hidden"><!--Session data--><input onclick="jsCall();" id="jsProxy" type="hidden"></p><div id="refHTML"></div><p><input id="gwProxy" type="hidden"><!--Session data--><input onclick="jsCall();" id="jsProxy" type="hidden"></p><div id="refHTML"></div><p><input id="gwProxy" type="hidden"><!--Session data--><input onclick="jsCall();" id="jsProxy" type="hidden"></p><div id="refHTML"></div>

Copyright © 2011 iNowWeb Web Design Company. All Rights Reserved.
Terms & Conditions | Privacy Policy

XHTML CSS