참조 문서 : https://tistory.github.io/document-tistory-apis/
최종 작업일 2020.02.18 ( 참조용 )
이메일주소와 ID를 입력하여 로그인
CallBack 이 중요. 나머지는 적당히 입력해도 상관 없음.
APP ID 와 Secret Key 는 매우 중요한 정보이므로 타인에게 노출되지 않도록 조심하기 바랍니다.
웹서비스를 구축해서 ACCESS_TOKEN 정보를 받아보도록 하겠습니다.
웹 프레임워크는 expressjs, 웹 호출용 request (또는 axios 설치해도 됨 ) , node 모니터링용 nodemon 이렇게 3개를 설치
$ mkdir web
$ cd web
$ npm init
(이후 enter 만 쳐서 일단 기본값으로 완료)
$ npm install express request
$ npm install -g nodemon
"main" : "app.js" 로 수정
인증에 필요한 부분만 구현
const express = require('express');
const path = require('path');
const request = require('request');
// init
const app = express();
// 라우팅 설정
app.get('/tistory/auth/res', function(req,res,body){
// client_id, redirect_uri 값 입력을 통해 Authentication Code 값을 얻어 온다.
// https://www.tistory.com/oauth/authorize?client_id=1fd6a4c18027723413ebedbb0b58c1f2&redirect_uri=http://localhost:3000/tistory/auth/res&response_type=code
let client_id = '위에서 생성한 자신의 APP ID 입력';
let client_secret = '위에서 생성한 자신의 Secret Key 입력';
let code = req.query.code;
let redirect_uri = 'http://localhost:3000/tistory/auth/res'; // 사용은 안되는데 누락되면 오류
let url = `https://www.tistory.com/oauth/access_token?client_id=${client_id}&client_secret=${client_secret}&code=${code}&redirect_uri=${redirect_uri}&grant_type=authorization_code`;
let options = {
url,
method : 'get',
timeout : 1000,
};
request(options, function (error, response, body) {
if(error){
res.send(error);
}else{
res.send(body);
}
});
});
// start server
const SERVER_PORT = 3000;
app.listen(SERVER_PORT, function(){
console.log(`server is started with http://localhost:${SERVER_PORT}`);
})
$ nodemon
위 주소 값에서
client_id,redirect_uri위 2가지 값을 확인한 후 접속한 다음 확인 버튼을 눌러 ACCESS_TOKEN 값을 확인한다
결과 예시
access_token=a39f1d**********************************
일단 ACCESS_TOKEN 을 확보 했다면 뭐 거의 다 완료 했다고 보면 됩니다. 이제 이것을 이용하여 글을 작성하면 됩니다. (다음편에 계속 ... ) https://tistory.github.io/document-tistory-apis/ 링크를 참조하면 API 활용 방법을 볼 수 있습니다.