Language:

Displaying the tweets from a Twitter profile via PHP

14 February 2011 | In Web | 2,2 thousand views | By

Click and share: 

We will learn how easy it is to view the tweets from any profile in Twitter on a page written in PHP. THE from This template you can create your custom page and display it as you wish.

Let's Schedule!

We will get the values via XML Feed. It is a relatively simple file, but to treat all the information you need to form original and concrete.

Let the script:

<?php
$usuario = 'dicasemgeral'; // Usuário do Twitter
$feed = 'http://twitter.com/statuses/user_timeline/'.$usuario.'.rss'; // Apenas o URL do Feed
$limite = 10; // Limite te Tweets que aparecerão na tela
?>
<html>
<head>
<title>Tweets de <?=$usuario;?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
$conta=0;
foreach(simplexml_load_file($feed)->channel->item as $item ): if($conta>=$limite){break;} $conta++;
$username = $usuario;
$nome = explode(':',$item->title); $nome = $nome[0];
$link = $item->link;
$data = $item->pubDate;
$tweet = str_replace($nome.': ','',$item->description);
?>
<div id="tweet<?=$conta;?>">
<a target="_blank" href="http://twitter.com/<?=$username;?>"><img src="http://api.twitter.com/1/users/profile_image/<?=$username;?>" border="0" style="float:left; padding:3px;" width="48" height="48" title="@<?=$username;?>" /></a><a title="@<?=$username;?>" target="_blank" href="http://twitter.com/<?=$username;?>"><b><?=$nome;?></b></a>: <?=$tweet;?>
<br>
<small><span><a href="<?=$link;?>" target="_blank" style="color:#444444; text-decoration:none;"><?=$data;?></a></span></small>
</div>
<div style="clear:both;"></div>
<?php
endforeach;
?>
</body>
</html>

The above script should return something like:

exibindo tweets php

The result, Surely, is organic, without formatting. Therefore, It's up to you the programmer to develop methods of style and create your custom page. An example of this you can see here. Note that chat works on the left side of the page.

Good luck! :)

In Ivaiporã-PR, Computer engineer, Group administrator Tips in General. Passionate about Technology and computer science.



Leave your comment

A bit about us

    The General Tips Group arose in 2007 from innovative ideas on troubleshooting problems faced daily by those who use the technology and computer science, both ordinary users and technicians. But where did, why and what is the purpose of this site?

Click here to know!

Give a +1 in Tips in General
     

Video of the week

Copyright (cc) 2014 - General Tips group - Privacy - Site map - Layout of the site produced by William Périgo - Created by Amilton Junior