twitter機能を連動
WEBサイトにtwitter機能を連動。
15分おきに、DBからランダムで情報を引っ張ってきてつぶやく機能を追加したのでメモ。
とても簡単。
ZendFrameworkのライブラリZend/Service/Twitter.phpを設置するだけ。
CakePHPから利用する場合はvendor配下にライブラリを設置し、zendを扱うコンポーネントを作成。
<?php App::import('Vendor', 'include_path_vendors'); require_once('/****/vendors/Zend/Service/Twitter.php'); define('TWITTER_LOGIN_ID','**********'); define('TWITTER_LOGIN_PASS','**********'); class TwitterManageComponent extends Object{ function write_comment($comment){ $twitter = new Zend_Service_Twitter(TWITTER_LOGIN_ID, TWITTER_LOGIN_PASS); //投稿 $response = $twitter->status->update($comment); } }
実際に使用したい処理からnewしてコメントを埋め込めばOK。簡単!
<?php $twitter_manage = new TwitterManageComponent(); $twitter_manage -> write_comment($write_comment); ?>
ちなみにZendのライブラリー内にはinclude_pathの設定を忘れずに。
<?php ini_set('include_path',get_include_path().PATH_SEPARATOR.'/home/****/www/****/cake/vendors'); ?>