Twitterから取り込みを行うだけ・・・のページを作ってみた。
※PHP版です。

最新30件だけ取ってくるだけ・・・・

例:私のTwitterアカウント taman777 を埋めた場合
↓IFRAMEの中に埋め込んだだけ・・・

ソースは追記に・・


下記を貼り付け・・・・て
twitCom.php て名前付けて保存
読み込みたい箇所に
<iframe src=”http://(※ファイルがある場所)/twitCom.php” width=”100%” frameborder=0>IFRAME非対応だと見ることが出来ません。</iframe>
みたいなタグを貼ればおしまい!
※下記の例だと・・・リリーフランキーさんとみうらじゅんさんのツイッターが表示される・・・はず

そして100000ミリ秒(100秒・・・かな)でリロードされます。


<?php
// ツイッターアカウント
$account = "LilyAndMJ_bot";
// 表示記事数
$kijiCount = 30;

//Twitter APIに接続
$contents = file_get_contents(‘http://search.twitter.com/search.atom?q=from:’.$account.’&rpp=’.$kijiCount);

//XMLをオブジェクトに変換
$xml = simplexml_load_string($contents);

// 記事数が表示記事数より少ない場合
$realKijiCount = 0;
for ($i = 0; $i < $kijiCount; $i++ ) {

//書き込み人の取得
$author_name = $xml->entry[$i]->author->name;
if ($author_name != "") {
$realKijiCount ++;
} else {
break;
}
}
if ($kijiCount > $realKijiCount) {
$kijiCount = $realKijiCount;
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript" language="javascript">
<!–
// タイマー更新
var timer = "100000"; //指定ミリ秒単位
function ReloadAddr(){
window.location.reload();
}
setTimeout(ReloadAddr, timer);
//–>
</script>
<style type="text/css">
<!–
.tweet-image {
margin: 1px;
padding: 1px;
height: 50px;
width: 50px;
float: left;
}
.tweet {
clear: both;
}
.tweet-content {
font-size: small;
float: left;
background-color: #FFFFCC;
border: 1px solid #999999;
padding: 5px;
}
–>
</style>
</head>
<body>

<?
for ($i = 0; $i < $kijiCount; $i++ ) {

//書き込み人の取得
$author_name = $xml->entry[$i]->author->name;
//書き込み人のユーザー名取得
$author_id = mb_split(‘\(‘,$author_name);
$id = mb_ereg_replace(‘ ‘,”,$author_id[0]);
$author_nm = mbsplit(‘\)’, $author_id[1]);
$screen_name = mb_ereg_replace(‘ ‘,”,$author_nm[0]);

// アイコン ツイッターアイコンイメージ取得API利用
// 詳細:http://img.tweetimag.es/
$iconUrl = "http://img.tweetimag.es/i/".$id."_n";

$link = $xml->entry[$i]->author->uri;

//本文の取得
$bunsho = $xml->entry[$i]->title;

//書き込み日の取得
$pdate = $xml->entry[$i]->published;
$pdate = date(‘Y/m/d H:i:s’,strtotime($pdate));
?>
<div class="tweet">
<div class="tweet-image">
<img height="48" width="48" src="<?=$iconUrl?>" alt="" data-user-id="<?=$id?>">
</div>
<div class="tweet-content">
<span class="tweet-user-name">
<a class="tweet-screen-name user-profile-link" data-user-id="<?=$id?>" href="<?=$link?>" title="<?=$author_name?>"><?=$screen_name?></a>
</span>
<div class="tweet-row">
<div class="tweet-text"><?=$bunsho?></div>
<div class="tweet-timestamp">(<?=$pdate?>)</div>
</div>
</div>
</div>
<?
}
?>
</body>
</html>


いろいろなところを参考にしました。
HTMLのエスケープツール利用しました。ありがとうございます。

この記事が気に入ったら
いいね ! しよう

Twitter で