http://channy.creation.net/project/twi2me/code.html
1. 요구 사항
- PHP 5.0+ 및 Cron 작업 환경
- Twitter API 및 JSON, Me2 PHP 라이브러리
2. 서비스 단계
- Me2day 애플리케이션키를 발급 받고 자신의 사용자키를 환경 설정 화면에서 발급 받는다.
- Twitter API 및 JSON, Me2 PHP 라이브러리를 다운로드 받는다.
- 아래 소스 코드에 애플리케이션 키, 사용자키, 트위터 아이디 등을 설정한다.
01.#!/usr/bin/php02.<?php03.// Include library04.require_once("lib/twitter.lib.php");05.require_once("lib/JSON.php");06.require_once("lib/Me2.php");07.08.//Account information09.Me2Api::$applicationKey='xxxxxxxxxxxxxxxxxxxxxxxxxxxx';// application key10.$me2_id=newMe2AuthenticatedUser('channy','xxxxxxxxx');// user key11.$twitter_id='channyun';12.13.// Setting up JSON and Twitter Library14.$json=newServices_JSON();15.$twitter=newTwitter($twitter_id,'');16.17.$twitter_messages=$twitter->getUserTimeline('json',$twitter_id);18.$result=$json->decode($twitter_messages);19.20.// catching last job time21.$last_job_time=strtotime("-10 minute")."\n";22.23.foreach($resultas$value) {24.// Writing messages that written in more than last job time.25.if($last_job_time<strtotime($value->created_at)) {26.$post=$me2_id->post(twitter_parse($value->text),'twitter', 9);27.}28.}29.30.31.// Parsing twitter text into me2day syntax32.functiontwitter_parse($str) {33.$str=explode("\n",$str);34.$str=implode("\n ",$str);35.$str=" ".$str;36.37.// case of urls39.$str=eregi_replace("\(http://([a-z0-9\_\-\.\/\~\@\?\=\;\&\#\-]+)\)","(\"http://\\1\":http://\\1 )",$str);40.$str=eregi_replace(" http://([a-z0-9\_\-\.\/\~\@\?\=\;\&\#\-]+)"," \"http://\\1\":http://\\1 ",$str);41.$str=eregi_replace(" http://([a-z0-9\_\-\.\/\~\@\?\=\;\&\#\-]+)"," \"http://\\1\":http://\\1 ",$str);42.// case of replies43.$str=eregi_replace(" (@[a-z0-9-]{1,})"," \"\\1\":http://twitter.com/\\1 ",$str);44.$str=eregi_replace("com/@","com/",$str);45.// case of hashtag46.$str=eregi_replace(" (#[a-z0-9-]{1,})"," \"\\1\":http://search.twitter.com/search?q=\\1 ",$str);47.48.return$str;49.}50.?> - Cron 작업에 아래와 같이 10분에 한번씩 작업을 걸어둔다.
1.0,10,20,30,40,50 * * * * /project/twi2me/cron.php&
'Interesting > TIPTECH' 카테고리의 다른 글
| HTC에서 제시한 충전법 (0) | 2010.08.25 |
|---|---|
| 모바일에서도 PC에서처럼 편리하게 유튜브를 즐기세요~ (0) | 2010.08.25 |
| 넥서스원 런처프로그램을 이용해 최적화 하기 (2) | 2010.08.18 |
| URL 줄이기와 QR코드 만드는 방법 (0) | 2010.08.18 |
| 구글 Chrome to Phone (0) | 2010.08.17 |