알림
이 애플리케이션은 고급 개발자만이 사용할 수 있는 프로그램입니다. 일반 사용자인 경우 미투데이 사용자키가 노출되는 보안 위험 때문에 웹 서비스로 만들지는 않았습니다. 혹시 함께 사용하시고 싶은 분은 Twitter 서비스 신청을 해주시기 바랍니다.
이 애플리케이션은 고급 개발자만이 사용할 수 있는 프로그램입니다. 일반 사용자인 경우 미투데이 사용자키가 노출되는 보안 위험 때문에 웹 서비스로 만들지는 않았습니다. 혹시 함께 사용하시고 싶은 분은 Twitter 서비스 신청을 해주시기 바랍니다.
1. 요구 사항
- PHP 5.0+ 및 Cron 작업 환경
- Twitter API 및 JSON, Me2 PHP 라이브러리
2. 서비스 단계
- Me2day 애플리케이션키를 발급 받고 자신의 사용자키를 환경 설정 화면에서 발급 받는다.
- Twitter API 및 JSON, Me2 PHP 라이브러리를 다운로드 받는다.
- 아래 소스 코드에 애플리케이션 키, 사용자키, 트위터 아이디 등을 설정한다.
#!/usr/bin/php <?php // Include library require_once("lib/twitter.lib.php"); require_once("lib/JSON.php"); require_once("lib/Me2.php"); //Account information Me2Api::$applicationKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // application key $me2_id = new Me2AuthenticatedUser('channy', 'xxxxxxxxx'); // user key $twitter_id = 'channyun'; // Setting up JSON and Twitter Library $json = new Services_JSON(); $twitter = new Twitter($twitter_id,''); $twitter_messages = $twitter->getUserTimeline('json', $twitter_id); $result = $json->decode($twitter_messages); // catching last job time $last_job_time= strtotime("-10 minute")."\n"; foreach($result as $value) { // Writing messages that written in more than last job time. if($last_job_time < strtotime($value->created_at)) { $post = $me2_id->post(twitter_parse($value->text), 'twitter', 9); } } // Parsing twitter text into me2day syntax function twitter_parse($str) { $str=explode("\n",$str); $str=implode("\n ",$str); $str=" ".$str; // case of urls $str = eregi_replace( ">http://([a-z0-9\_\-\.\/\~\@\?\=\;\&\#\-]+)", ">\"http://\\1\":", $str); $str = eregi_replace( "\(http://([a-z0-9\_\-\.\/\~\@\?\=\;\&\#\-]+)\)", "(\"http://\\1\":http://\\1 )", $str); $str = eregi_replace( " http://([a-z0-9\_\-\.\/\~\@\?\=\;\&\#\-]+)", " \"http://\\1\":http://\\1 ", $str); $str = eregi_replace( " http://([a-z0-9\_\-\.\/\~\@\?\=\;\&\#\-]+)", " \"http://\\1\":http://\\1 ", $str); // case of replies $str = eregi_replace(" (@[a-z0-9-]{1,})", " \"\\1\":http://twitter.com/\\1 ", $str); $str = eregi_replace("com/@", "com/", $str); // case of hashtag $str = eregi_replace(" (#[a-z0-9-]{1,})", " \"\\1\":http://search.twitter.com/search?q=\\1 ", $str); return $str; } ?> - Cron 작업에 아래와 같이 10분에 한번씩 작업을 걸어둔다.
0,10,20,30,40,50 * * * * /project/twi2me/cron.php&
트윗을 미투데이로 보내기