블로그 이미지
푸른_바람

Rss feed Tistory
IT/Tech 2010/02/19 19:48

me2day api PHP

me2day api

me2day api를 사용해서 서비스를 개발해야 된다. 으윽 머리아파

일단 관련 자료를 URL로 정리해보겠습니다.


미투데이에 초대합니다!! – マサキ君の色んな考え

이미지출처 : ayukawa.80port.net


미투데이
미투데이 APP
me2py 공개 (python module for me2day open API)

me2day php API 소스

위의 자료를 바탕으로 테스트를 위한 코드를 만들었습니다.
[code php]
class Me2api {
public $user_id = null;
public $user_key = null;
public $format = 'xml';
private $api_url = 'http://me2day.net:80';
private $application_key = '';

public function Me2api(){
}

public function _getNonce(){
$nonce = '';
for($i=0; $i<8; $i++) $nonce .= dechex(mt_rand(0,15));
//for($i=0; $i<8; $i++) $nonce .= dechex(rand(0,15));
return $nonce;
}

public function _getAuthKey(){
$nonce = $this->_getNonce();
return $nonce.md5($nonce.$this->user_key);
}

public function _getPath($method, $user_id=nll){
return ($user_id)?
sprintf('/api/%s.'.$this->format, $method):
sprintf('/api/%s/%s.'.$this->format, $method, $this->user_id);
}

public function _get_me2day($method, $user_id=null, $params=null){
$url = $this->api_url.$this->_getPath($method, $user_id);
$auth = base64_encode($this->user_id.':'.$this->_getAuthKey());

$arr_content = array();
if(is_array($params) && count($params)) {
foreach($params as $key => $val) {
$arr_content[] = sprintf('%s=%s', $key, urlencode($val));
}
$body = implode('&',$arr_content);
}
$url .= '?'.$body;
$file = fopen ($url, "r");
if (!$file) {
echo "<p>Unable to open remote file.\n";
exit;
}
$buff = '';
while (!feof ($file)) $buff .= fgets ($file, 1024);
fclose($file);
return $buff;
}
}

class me2{
public $var = Array(
'user_id' => null;
'user_key' => null;
);

public function m2(){
$this->var = (object)$this->var;
$me2api = new Me2api;
$content = $this->me2api->_getContent('get_latests', $this->var->user_id, Array('content_type'=>'document'));
print_r($content);
}
}
[/code]

일단 코드 전체를 타이핑하기 귀찮아서(텍스트큐브 코드 라이브러리와 글쓰기 에디터 화면은 같이 사용하기가...) 이만큼만 적고 담에 또 추가 하겠습니다.

볼만한건 없지만... 되도록 하루에 하나씩 포스팅을 하기 위해서 노력중입니다. ^^


'IT > Tech' 카테고리의 다른 글

naver.com 나눔글꼴 설치  (0) 2010/04/02
javascript object 값 출력  (2) 2010/03/10
me2day api PHP  (0) 2010/02/19
PHP 성능튜닝 IF & Switch 문법  (0) 2010/01/28
프로그램에서 메일수신확인 방법  (0) 2010/01/04
mypicup textcube용 위젯 스크립트  (0) 2009/12/30
TOTAL 246,630 TODAY 8