<?php
$twitter_url = 'http://twitter.com/statuses/user_timeline/ishrikrishna.xml?count=1';
$buffer = file_get_contents($twitter_url);
$xml = new SimpleXMLElement($buffer);
$status = $xml -> status;
$tweet = $status -> text;
echo $tweet;
?>
このコードを使用してツイートを取得しましたが、localhost では正常に動作しましたが、私の Web ホストでは動作しませんでした。このスクリプトを 2 つの Web ホスティング サービスで試しました。
私が気付いた問題は、file_get_contents()、simplexml_load_file() などの関数が、別のサーバーに保存されている xml ファイル (例: rss ファイル) からデータを取得できなかったことです。