Create your own twitter image signature

Many days ago i built two image signature as my forum signature. One of the signature shows the latest post from my blog and another shows my latest twitter update. I was inspired to do that signature by seeing Shiplu Vai’s signature. Originally he was using them and i copied the concept :D

Anyway, here is my latest blog post signature Blog Update Signature and here is my twitter signature Twitter image signature

I will show you the process to create your own twitter image signature like me.

1. At first we will get the latest twitter update by this

<?php
$username = "tareq_cse"; //Twitter Username
$url = "http://twitter.com/statuses/user_timeline/$username.json?count=1"; //json request url
$json = json_decode(file_get_contents($url));
$status = $json[0]->text; //get the status from array/object

2. Now we will get the time distance from now and the twitted time and will format it
Read the rest of this entry »

Playing with twitter JSON using PHP

Now twitter is playing a major roll to our day. Many of us is using twitter. Now lets play something with it. Today i will use JSON to play with twitter LOL.

Lets play with our statuses. If you are using twitter, then your status url is http://twitter.com/status/user_timeline/YOUR_USERNAME.json. So if your twitter id is tareq_cse then the url will be http://twitter.com/status/user_timeline/tareq_cse.json. Now i will add a extra parameter here and this is count. This url shows the last 20 status update of yours. So if i need only 5 update then? Then we will add a count variable there. So the url will be http://twitter.com/status/user_timeline/tareq_cse.json?count=5

Now come to the php code.

<?php
$json = file_get_contents("http://twitter.com/status/user_timeline/tareq_cse.json?count=10", true); //getting the file content
$decode = json_decode($json, true); //getting the file content as array

echo "<pre>";
print_r($decode);
echo "</pre>";
?>

Now run the code and see. You will get output like this

Array
(
    [0] => Array
        (
            [text] => is digging wordpress
            [in_reply_to_user_id] =>
            [user] => Array
                (
                    [notifications] =>
                    [time_zone] => Dhaka
                    [description] => A blogger, microblogger and learner
                    [following] =>
                    [utc_offset] => 21600
						...............
						...............
                    [profile_text_color] => 666666
                    [location] => Rajshahi, Bangladesh
                    [id] => 15842888
                    [profile_background_image_url] => http://static.twitter.com/images/themes/theme9/bg.gif
                    [profile_link_color] => 2FC2EF
                )

            [favorited] =>
            [in_reply_to_screen_name] =>
            [truncated] =>
            [created_at] => Sun May 03 20:56:00 +0000 2009
            [id] => 1689697302
            [in_reply_to_status_id] =>
            [source] => TwitterFox
        )
)

Now get some usefull data from this. If we need the last 10 twitter update write the code

<?php
$json = file_get_contents("http://twitter.com/status/user_timeline/tareq_cse.json?count=10", true);
$decode = json_decode($json, true);

echo "<pre>";
$count = count($decode); //counting the number of status
for($i=0;$i<$count;$i++){
echo $decode[$i][text]."<br>";
}
echo "</pre>";
?>

Lets pull some userdata

<?php
$json = file_get_contents("http://twitter.com/status/user_timeline/tareq_cse.json?count=10", true);
$decode = json_decode($json, true);

echo "<img src=\"".$decode[0][user][profile_image_url]."\"</img><br>"; //getting the profile image
echo "Name: ".$decode[0][user][name]."<br>"; //getting the username
echo "Web: ".$decode[0][user][url]."<br>"; //getting the web site address
echo "Location: ".$decode[0][user][location]."<br>"; //user location
echo "Updates: ".$decode[0][user][statuses_count]."<br>"; //number of updates
echo "Follower: ".$decode[0][user][followers_count]."<br>"; //number of followers
echo "Following: ".$decode[0][user][friends_count]."<br>"; // following
echo "Description: ".$decode[0][user][description]."<br>"; //user description
?>

Following this method, you can pull any data by analyzing the first output

Tags: , ,