node-tistory๋ Tistory์ ์คํ API๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํ Node.js ๋ชจ๋์ด๋ค.
node-tistory๋ global๋ก ์ค์นํ๊ธฐ ์ํด์ ๋ค์๊ณผ ๊ฐ์ด npm install -g๋ก ์ค์นํ ์ ์๋ค.
npm install -g node-tistory
๊ธ๋ก๋ฒ ์ค์นํ ํ tistory ๋ช
๋ น์ด๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
tistory -help
npm install node-tistory
local module๋ก ์ค์นํ ๊ฒฝ์ฐ ๋ค์๊ณผ ๊ฐ์ด ์ฌ์ฉํ ์ ์๋ค.
var Tistory = require('node-tistory');node-tistory๋ $HOME/.tistory.json ํ์ผ์ ๊ธ๋ก๋ฒ ์ค์ ํ์ผ๋ก ์ฝ์ด๋ค์ธ๋ค.
node-tistory๋ฅผ ์ฌ์ฉํ ๋ ํ์ํ ์ต์
์ ๋ณด๋ฅผ .tistory.json์ ๋ฏธ๋ฆฌ ์ ์ฅํด๋๋ฉด ํญ์ ์ด ์ค์ ํ์ผ์ ๋จผ์ ์ฝ์ด์ ์ต์
์ ๋ณด๋ก ์ค์ ํ๋ค.
echo '{
"targetUrl": "Tistory URL",
"access_token": "Tistory API access_token",
"output": "json"
}' > ~/.tistory.jsonTistory์์ ์ ๊ณตํ๊ณ ์๋ ์คํ API ๊ฐ์ด๋ ๋ฅผ ์ฐธ๊ณ ํ๋ฉด ๋๋ค.
node-tistory ์์๋ Tistory์ ์คํ API๋ฅผ ๊ฐ๋จํ๊ฒ ๋ฐ๋ก ์ฌ์ฉํ ์ ์๋๋ก ๋ฉ์๋ ํํ์ interface๋ฅผ ์ ๊ณตํ๊ณ ์๋ค.
| ๋ชจ๋ | ์ธํฐํ์ด์ค | Tistory API | ์ค๋ช |
|---|---|---|---|
| blog | info | /apis/blog/info | ๋ธ๋ก๊ทธ ์ ๋ณด |
| post | list | /apis/post/list | ๊ธ ๋ชฉ๋ก |
| read | /apis/post/read | ๊ธ ๋ณด๊ธฐ | |
| write | /apis/post/write | ๊ธ ์ฐ๊ธฐ | |
| modify | /apis/post/modify | ๊ธ ์์ | |
| attach | /apis/post/attach | ํ์ผ์ฒจ๋ถ | |
| category | list | /apis/category/list | ๋ถ๋ฅ ๋ชฉ๋ก |
| find | ๋ถ๋ฅ ๊ฒ์ |
๋ชจ๋ interface ๋ฉ์๋๋ params, callback์ ์ธ์๊ฐ์ผ๋ก ์ฌ์ฉํ๋ค. params๋ Object ํํ์ด๊ณ callback์ err,body,res ๊ฐ์ ๋ฐ๋ ํจ์ ํํ์ด๋ค.
params์ key๋ Tistory ์คํ API์ Request Parameter์ ์ด๋ฆ๊ณผ ๋์ผํ๋ค.
e.g. ํฐ์คํ ๋ฆฌ ๋ธ๋ก๊ทธ http://blog.saltfactory.net ์ ๋ณด ๋ณด๊ธฐ
var params = {
targetUrl:'blog.satlfactory.net'
};
var callback = function(err, body, res){
console.log(body);
};
tistory.blog.info(params, callback);e.g. http://blog.saltfactory.net์ ๊ธ ๋ชฉ๋ก๋ณด๊ธฐ
var params = {
page: 1,
count: 10
};
tistory.post.list(params, function(err, body, res){
console.log(body);
});node-tistory์ ์ธํฐํ์ด์ค์ ํ๋ผ๋ฏธํฐ๋ Object ํํ๋ก ์ง์ ํ๋ค.
var params = {
'targetUrl':'blog.saltfactory.net'
};| params | ๊ฐ | ์ค๋ช | ํ์ |
|---|---|---|---|
| access_token | String | OAuth 2.0 ์ธ์ฆ ํ ํ๋ํ access_token | ํ์ |
| targetUrl | String | http://saltfactory.tistory.com ๊ณผ ๊ฐ์ด 1์ฐจ ๋๋ฉ์ธ ๊ฒฝ์ฐ saltfactory, http://blog.saltfactory.net ๊ณผ ๊ฐ์ด 2์ฐจ ๋๋ฉ์ธ์ผ ๊ฒฝ์ฐ blog.saltfactory.net | ํ์ |
| output | 'json','xml' | ๊ธฐ๋ณธ๊ฐ 'json' | ์ต์ |
| ์์ | ์์ | ํ๋ผ๋ฏธํฐ ์์ด ์ฝ๋ฐฑํจ์๋ง ์ฌ์ฉ ๊ฐ๋ฅ | ์์ |
| params | ๊ฐ | ์ค๋ช | ํ์ |
|---|---|---|---|
| access_token | String | OAuth 2.0 ์ธ์ฆ ํ ํ๋ํ access_token | ํ์ |
| targetUrl | String | ๋ธ๋ก๊ทธ URL | ํ์ |
| output | 'json','xml' | ๊ธฐ๋ณธ๊ฐ 'json' | ์ต์ |
| page | Number | ํด๋น ํ์ด์ง ๊ธ ๋ชฉ๋ก, ๊ธฐ๋ณธ๊ฐ 1 | ์ต์ |
| count | 1~30 | ํ์ด์ง๋น ๊ธ ๊ฐฏ์, ๊ธฐ๋ณธ๊ฐ 10 | ์ต์ |
| categoryId | Number | ๋ถ๋ฅ์ ํด๋นํ๋ ๊ธ ๋ชฉ๋ก, ๊ธฐ๋ณธ๊ฐ ์ ์ฒด | ์ต์ |
| sort | 'id' or 'date' | 'id'๋ ๊ธ๋ฒํธ, 'date'๋ ์์ฑ๋ ์ง, ๊ธฐ๋ณธ๊ฐ id |
์ต์ |
| params | ๊ฐ | ์ค๋ช | ํ์ |
|---|---|---|---|
| access_token | String | OAuth 2.0 ์ธ์ฆ ํ ํ๋ํ access_token | ํ์ |
| targetUrl | String | ๋ธ๋ก๊ทธ URL | ํ์ |
| postId | Number | ๊ธ ๋ฒํธ | ํ์ |
| output | 'json','xml' | ๊ธฐ๋ณธ๊ฐ 'json' | ์ต์ |
| params | ๊ฐ | ์ค๋ช | ํ์ |
|---|---|---|---|
| access_token | String | OAuth 2.0 ์ธ์ฆ ํ ํ๋ํ access_token | ํ์ |
| targetUrl | String | ๋ธ๋ก๊ทธ URL | ํ์ |
| title | String | ๊ธ ์ ๋ชฉ | ํ์ |
| content | String | ๊ธ ๋ด์ฉ | ์ต์ |
| visibility | 0,1,2,3 | 0:๋น๊ณต๊ฐ, 1:๋ณดํธ, 2:๊ณต๊ฐ, 3:๋ฐํ, ์๋ต์ 0 | ์ต์ |
| published | String | UNIX_TIMESTAMP() ์์ฝ๋ฐ์ก | ์ต์ |
| tag | String | ,๋ฅผ ์ฌ์ฉํ์ฌ ์ฌ๋ฌ๊ฐ ํ๊ทธ ๋ฌธ์์ด | ์ต์ |
| output | 'json','xml' | ๊ธฐ๋ณธ๊ฐ 'json' | ์ต์ |
| params | ๊ฐ | ์ค๋ช | ํ์ |
|---|---|---|---|
| access_token | String | OAuth 2.0 ์ธ์ฆ ํ ํ๋ํ access_token | ํ์ |
| targetUrl | String | ๋ธ๋ก๊ทธ URL | ํ์ |
| postId | Number | ์์ ํ ๊ธ ๋ฒํธ | ํ์ |
| title | String | ๊ธ ์ ๋ชฉ | ํ์ |
| content | String | ๊ธ ๋ด์ฉ | ์ต์ |
| visibility | 0,1,2,3 | 0:๋น๊ณต๊ฐ, 1:๋ณดํธ, 2:๊ณต๊ฐ, 3:๋ฐํ, ์๋ต์ 0 | ์ต์ |
| published | String | UNIX_TIMESTAMP() ์์ฝ๋ฐ์ก | ์ต์ |
| tag | String | ,๋ฅผ ์ฌ์ฉํ์ฌ ์ฌ๋ฌ๊ฐ ํ๊ทธ ๋ฌธ์์ด | ์ต์ |
| output | 'json','xml' | ๊ธฐ๋ณธ๊ฐ 'json' | ์ต์ |
| params | ๊ฐ | ์ค๋ช | ํ์ |
|---|---|---|---|
| access_token | String | OAuth 2.0 ์ธ์ฆ ํ ํ๋ํ access_token | ํ์ |
| targetUrl | String | ๋ธ๋ก๊ทธ URL | ํ์ |
| uploadedfile | String | ํ์ผ๊ฒฝ๋ก | ํ์ |
| output | 'json','xml' | ๊ธฐ๋ณธ๊ฐ 'json' | ์ต์ |
| params | ๊ฐ | ์ค๋ช | ํ์ |
|---|---|---|---|
| access_token | String | OAuth 2.0 ์ธ์ฆ ํ ํ๋ํ access_token | ํ์ |
| targetUrl | String | ๋ธ๋ก๊ทธ URL | ํ์ |
| output | 'json','xml' | ๊ธฐ๋ณธ๊ฐ 'json' | ์ต์ |
| params | ๊ฐ | ์ค๋ช | ํ์ |
|---|---|---|---|
| access_token | String | OAuth 2.0 ์ธ์ฆ ํ ํ๋ํ access_token | ํ์ |
| targetUrl | String | ๋ธ๋ก๊ทธ URL | ํ์ |
| name | String | ๋ถ๋ฅ๋ช | ํ์ |
| output | 'json','xml' | ๊ธฐ๋ณธ๊ฐ 'json' | ์ต์ |
Tistory์ ๋ชจ๋ API๋ access_token, targetUrl ๊ทธ๋ฆฌ๊ณ output ํ๋ผ๋ฏธํฐ๋ฅผ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ node-tistory์ global configuration file์ธ
$HOME/.tistory.json์ ๋ค์๊ณผ ๊ฐ์ด ์ ์ฅํด๋๋ฉด ํ๋ผ๋ฏธํฐ๋ก ์ค์ ํ์ง ์์๋ ๋๋ค.
{
"targetUrl": "blog.saltfactory.net",
"access_token": "access_token",
"output": "json"
}var params = {
page:1,
count:10
};
tistory.post.list(params, function(err,body){
console.log(body);
});node-tistory๋ฅผ npm install -g๋ก ์ค์น๋ฅผ ํ๋ฉด tistory ๋ช
๋ น์ด๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
๋ง์ฝ $HOME/.tistory.json ํ์ผ์ ์ค์ ์ด ์ ์ฅ๋ ์ํ๋ผ๊ณ ์๊ฐํ๋ฉด ๋ช
๋ น์ด ์ฌ์ฉ์ ๋ค์๊ณผ ๊ฐ๋ค.
| ๋ช ๋ น์ด ์ต์ | ์ค๋ช |
|---|---|
| -help, --h | ๋์๋ง |
| -pretty | indent ์ถ๊ฐํด์ JSON ํ๋ฆฐํธ |
| ํ๋ผ๋ฏธํฐ ์ต์ | ์ค๋ช |
|---|---|
| -ํ๋ผ๋ฏธํฐ๋ช | ํ๋ผ๋ฏธํฐ์ ์ด๋ฆ ์์ -๋ฅผ ๋ถ์ด๊ณ ๋ค์ ๊ฐ์ ์ง์ |
tistory blog info -pretty
tistory post list -page 1 -count 10 -output json
tistory post read 105 --pretty
tistory post write -title ์๋
ํ์ธ์ -content ํ
์คํธ์
๋๋ค. -tag ํ๊ทธ1,ํ๊ทธ2
tistory post write -postId 105 -title ์๋
ํ์ธ์ -content ํ
์คํธ์
๋๋ค. -tag ํ๊ทธ1,ํ๊ทธ2
tistory post attach -file /Users/saltfactory/Documents/test.png
tistory category list --pretty
tistory category find Node.js --pretty
The MIT License (MIT)
Copyright (c) 2014 SungKwang Song
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.