PHPからTwitterにPostする方法

function postTwitter($message) { $url = "http://twitter.com/statuses/update.xml?"; $username = "hoge"; $password = "hogehoge"; $params = "status=".urlencode(mb_convert_encoding($message, "UTF-8", "auto")); $result = file_get_contents($url.$params , false, stream_context_create(array( "http" => array( "method" => "POST", "header" => "Authorization: Basic ". base64_encode($username. ":". $password) ) ))); }

username と password のところに自分のアカウントのId/Passを入れればおk

UTF-8でURLエンコードをかまさないと日本語が化けちゃいます。

PEAR::Services_ShortURLfunction postTwitter($message) { $url = "http://twitter.com/statuses/update.xml?"; $username = "nicoinfo"; $password = "nicoinfo246"; $params = "status=".urlencode(mb_convert_encoding($message, "UTF-8", "auto")); $result = file_get_contents($url.$params , false, stream_context_create(array( "http" => array( "method" => "POST", "header" => "Authorization: Basic ". base64_encode($username. ":". $password) ) ))); }