Users Timeline On My Website


#1

I want to make a widget for my website. In this widget the users of my website they will be able to connect to twitter and then the widget will shows their timeline. Is this possible?
Thank you in advance


#2

PHP or JavaScript (jQuery) ?

PHP example

<?php

$username = “jimis_fou”;

$readurl = “http://twitter.com/statuses/user_timeline/".$username.".json”;

$rdata = json_decode(file_get_contents($readurl));

echo “
\r\n”;

print_r($rdata);

echo “\r\n”;

function url2link ($string, $target="_blank") {

preg_match_all(’|(http://[^\s]+)|’, $string, $matches1);
if($matches1) {
foreach($matches1[0] as $match1) {
$hypertext = “<a href=”".$match1."" target="".$target."">".$match1."";
$string = str_replace($match1, $hypertext, $string);
}
}

preg_match_all(’|(@[^\s]+)|’, $string, $matches2);
if($matches2) {
foreach($matches2[0] as $match2) {
$hypertext = “<a href=“http://twitter.com/”.$match2.”" target="".$target."">".$match2."";
$string = str_replace($match2, $hypertext, $string);
}
}

return $string;
}

foreach($rdata as $ritem) {

$showtext = $ritem->text;

$showtext = utf8_decode($showtext);
$showtext = url2link($showtext);

$status_timestamp = strtotime($ritem->created_at);
$status_locdate = date(“Y-m-d (H:i:s)”,$status_timestamp);

echo “<p style=“text-align:left; width:570px; clear:both;”>\r\n”;
echo “<a href=“http://twitter.com/”.$ritem->user->screen_name.”" title="".$ritem->user->name."" target="_blank"><img src="".$ritem->user->profile_image_url."" alt="".$ritem->user->name."" align=“left” width=“48” height=“48” border=“0” style=“padding:10px 8px 2px 0px;” />\r\n";
echo " <a href=“http://twitter.com/”.$ritem->user->screen_name."" title="".$ritem->user->name."" target="_blank"><strong style=“font-size:140%;”>".$ritem->user->screen_name."    “.$ritem->user->name.” \r\n";
echo “<span style=“padding:0px 12px 0px 0px; float:right;”>”.$status_locdate."\r\n";
echo “
\r\n”;
echo “<span style=“display:block; margin:2px 0px 2px 54px; padding:6px; background:#DEDEDE; color:#000000;”>”.$showtext."\r\n";
echo "
 \r\n";
echo “

\r\n”;

}
?>

jQuery example



 


have fun.


#3

index,php ???


#4

This no longer works because http://twitter.com/statuses/user_timeline/".$username.".json no longer exists


#5

Awesome @10games! I’m new to PHP and I’m not finding the documentation particularly helpful (coming from JavaScript) and the ability to pull values from an object with $ritem->user->name totally made my day!


#6