Twitterの最新ツイートを、jQuery と PHP で取得する2つの方法 - Inspiration And Reminder Diary

Inspiration And Reminder Diary ホーム » PHP »  Twitterの最新ツイートを、jQuery と PHP で取得する2つの方法

Twitterの最新ツイートを、jQuery と PHP で取得する2つの方法

まず、
PHP で取得する方法について


function parse_feed($feed)
{
$stepOne = explode("<content type=\"html\">", $feed);
$stepTwo = explode("</content>", $stepOne[1]);
$tweet = $stepTwo[0];
$tweet = str_replace("&lt;", "<", $tweet);
$tweet = str_replace("&gt;", ">", $tweet);
return $tweet;
}

function getTweet($name)
{
$feed = "http://search.twitter.com/search.atom?q=from:".$name."&rpp=1";
$twitterFeed = file_get_contents($feed);
echo parse_feed($twitterFeed);
}
getTweet('user')


user の部分を自分のユーザー名に変更する。

jQuery で取得する方法

$.getJSON("http://twitter.com/statuses/user_timeline/AUTHORITY_SITE.json?callback=?", function(data) {
$("#theIdOfTheElement").html(data[0].text);
});


<div id="theIdOfTheElement">ここに最新ツイートが表示される</div>


theIdOfTheElement は自分の好きな名前に変更して良です。

wpcanyon "2-different-ways-for-getting-twitter-status-php-and-jquery"

コメント
非公開コメント

トラックバック

http://samurai614.blog29.fc2.com/tb.php/20-f8c50bc9