2012-04-20 9 views
0

私は最新のつぶやきのツイッターフィードを取り込むために使用しようとしている以下のコードが動作していないのはなぜですか?Twitterフィードはコードを使用していませんか?

CODE:

<? 
    $username = "readitforward"; 
    $limit = 5; 
    $feed = 'http://twitter.com/statuses/user_timeline.rss?screen_name='.$username.'&count='.$limit; 
    $tweets = file_get_contents($feed); 

     $tweets = str_replace("&", "&", $tweets); 
     $tweets = str_replace("<", "<", $tweets); 
     $tweets = str_replace(">", ">", $tweets); 
     $tweet = explode("<item>", $tweets); 
    $tcount = count($tweet) - 1; 

for ($i = 1; $i <= $tcount; $i++) { 
    $endtweet = explode("</item>", $tweet[$i]); 
    $title = explode("<title>", $endtweet[0]); 
    $content = explode("</title>", $title[1]); 
     $content[0] = str_replace("&#8211;", "&mdash;", $content[0]); 

     $content[0] = preg_replace("/(http:\/\/|(www\.))(([^\s<]{4,68})[^\s<]*)/", '<a href="http://$2$3" target="_blank">$1$2$4</a>', $content[0]); 
     $content[0] = str_replace("$username: ", "", $content[0]); 
     $content[0] = preg_replace("/@(\w+)/", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $content[0]); 
     $content[0] = preg_replace("/#(\w+)/", "<a href=\"http://search.twitter.com/search?q=\\1\" target=\"_blank\">#\\1</a>", $content[0]); 
    $mytweets[] = $content[0]; 
} 

while (list(, $v) = each($mytweets)) { 
    $tweetout .= "<div>$v</div>\n"; 
} 
?> 

出力ERROR:

Warning: file_get_contents() [function.file-get-contents]: http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /data/24/1/0/139/1815302/user/1967139/htdocs/RIF/wp-content/themes/crown_readitforward2012/sidebar.php on line 93 

Warning: file_get_contents(http://twitter.com/statuses/user_timeline.rss?screen_name=readitforward&count=5) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /data/24/1/0/139/1815302/user/1967139/htdocs/RIF/wp-content/themes/crown_readitforward2012/sidebar.php on line 93 

Warning: Variable passed to each() is not an array or object in /data/24/1/0/139/1815302/user/1967139/htdocs/RIF/wp-content/themes/crown_readitforward2012/sidebar.php on line 114 

ライン93:$tweets = file_get_contents($feed);

ライン114:while (list(, $v) = each($mytweets)) {

私はここで間違って何をしました?

答えて

1

php.iniを開き、allow_url_fopenを有効にします。これはini_set()で行うことはできません。

または、URLを要求する別の方法(cURLなど)を使用します。

+0

おかげで多くのことを。私は思ったphp.iniファイルを作成する必要があります。私はWordpressのインストールのルートディレクトリにファイルを作成しました。この変更を行うには、そこにコード化する必要があります。どうもありがとう。 –

+0

'phpinfo()'は、現在の場所を教えてください。 – alex

+0

もう一度おねがいしますが、そのスニペットで.iniファイルを見つけるにはどうすればよいですか? –

2

TwitterのAPIアップデートを確認してください。

はあなたの $feed変数に変更し

:手順については、

$feed = 'http://api.twitter.com/1/statuses/user_timeline.rss?screen_name='.$username.'&count='.$limit; 
関連する問題