PyTistory¶
PyTistory는 티스토리 오픈 API 가이드 를 참고하여 Python으로 작성한 티스토리 API 클라이언트입니다. 티스토리 오픈 API 가이드 인증 방식 중 Client-side flow 방식에 따라 구현되었습니다.
사용법¶
시작하기¶
티스토리 서비스 등록¶
먼저, 티스토리 API를 사용하기 위해 OAuth 과정을 거쳐야합니다. 그를 위해 티스토리 API client_id가 필요합니다. 그를 위해 티스토리 오픈 API 인증 가이드에서, 클라이언트 등록을 합니다.

서비스 형태와 서비스 권한, Callback 경로를 적절하게 수정해야 합니다.
서비스 형태는 PC 애플리케이션
으로, Callback 경로는 http://0.0.0.0:5000/callback
으로 설정합니다. 서비스 권한은
사용하실만큼 설정하시면 됩니다. 하지만, 읽기/쓰기
를 권장드립니다.
사용자 인증¶
인증정보는 다음과 같은 우선순위를 통해 적용됩니다.
- 직접 설정하는
configure
함수로 넘어오는access_token
인자값configure
함수로 넘어오는client_id
,tistory_id
,tistory_password
인자값configure
함수로 넘어오는file_name
에서 읽어들인 인자값- 환경변수값
- 기본 파일(
~/.pytistory/credentials.ini
)에 설정되어 있는 값
즉, 환경변수, 기본 설정 파일에 client id가 적용되어 있다 하더라도 직접 넘기는 file_name
에 존재하는 설정들에 의해 덮어씌워지고,
직접 인자값으로 넘기는 client_id
등의 인자값에 의해 덮어씌워집니다.
access_token
이 인자로 넘어올 경우 다른 옵션은 전부 무시하고, access_token
만을 설정합니다.
직접 Access Token 설정¶
from pytistory import PyTistory
pytistory = PyTistory()
pytistory.configure(
access_token='some-example-access-token')
함수의 인자값을 통한 설정¶
from pytistory import PyTistory
pytistory = PyTistory()
pytistory.configure(
client_id='some-example-client-id',
tistory_id='some-example-tistory-id',
tistory_password='some-example-tistory-password')
파일을 통한 설정¶
from pytistory import PyTistory
pytistory = PyTistory()
pytistory.configure(
file_name='./some/path/to/credentials.ini')
파일 형식¶
파일 형식은 ini(Initialization)을 따릅니다.
[pytistory]
client_id=some-client-id
tistory_id=some-tistory-id
tistory_password=some-tistory-password
환경변수를 통한 설정¶
환경 변수로는 다음과 같이 설정할 수 있습니다.
export PYTISTORY_CLIENT_ID=some-example-client-id
export PYTISTORY_TISTORY_ID=some-example-tistory-id
export PYTISTORY_TISTORY_PASSWORD=some-example-tistory-password
Blog API¶
Blog 정보 조회¶
블로그 정보를 받아오는 API입니다. 해당 API에 관한 정보는 링크 를 통해 살펴보실 수 있습니다.
from pytistory import PyTistory
pytistory = PyTistory()
pytistory.configure()
response = pytistory.blog.info()
결과값은 아래처럼 받을 수 있습니다.
{
"status": "200",
"id": "blogtest_080@hanmail.net",
"item": [
{
"url": "http://oauth.tistory.com",
"secondaryUrl": "http://",
"nickname": "Tistory API",
"title": "나만의 앱, Tistory OAuth API 로 만들어보세요!",
"description": "",
"default": "Y",
"blogIconUrl":
"http://i1.daumcdn.net/cfs.tistory/blog/79/795307/index.gif",
"faviconUrl":
"http://i1.daumcdn.net/cfs.tistory/blog/79/795307/index.ico",
"profileThumbnailImageUrl":
"http://cfile1.uf.tistory.com/R106x0/1851DB584DAF942950AF29",
"profileImageUrl":
"http://cfile1.uf.tistory.com/R106x0/1851DB584DAF942950AF29",
"statistics": {
"post": "3",
"comment": "0",
"trackback": "0",
"guestbook": "0",
"invitation": "0"
}
},
{
"url": "http://oauth2.tistory.com",
"secondaryUrl": "http://",
"nickname": "Tistory API",
"title": "나만의 비밀 홈",
"description": "",
"default": "N",
"blogIconUrl":
"http://i1.daumcdn.net/cfs.tistory/blog/79/795308/index.gif",
"faviconUrl":
"http://i1.daumcdn.net/cfs.tistory/blog/79/795308/index.ico",
"profileThumbnailImageUrl": "",
"profileImageUrl": "",
"blogId": "795308",
"statistics": {
"post": "0",
"comment": "0",
"trackback": "0",
"guestbook": "0",
"invitation": "0"
}
}
]
}
Post API¶
게시글 목록 조회¶
최근 게시물 목록을 가져올 수 있는 API입니다. 해당 API에 관한 정보는 게시물 목록 API 를 통해 살펴보실 수 있습니다.
from pytistory import PyTistory
pytistory = PyTistory()
pytistory.configure()
response = pytistory.post.list(blog_name='oauth')
결과값은 아래처럼 받을 수 있습니다.
{
"status": "200",
"item": {
"url": "http://oauth.tistory.com",
"secondaryUrl": "",
"page": "1",
"count": "10",
"totalCount": "4",
"posts": {
"post": [
{
"id": "4",
"title": "티스토리 OAuth Open API 일단 써보세요!",
"postUrl": "http://oauth.tistory.com /4",
"visibility": "0",
"categoryId": "0",
"comments": "6",
"trackbacks": "0",
"date": "1303796661"
},
{
"id": "3",
"title": "View에 보냅니다~",
"postUrl": "http://oauth.tistory.com /3",
"visibility": "3",
"categoryId": "0",
"comments": "0",
"trackbacks": "0",
"date": "1303372106"
},
{
"id": "2",
"title": "View에 보내봅니다.",
"postUrl": "http://oauth.tistory.com /2",
"visibility": "3",
"categoryId": "0",
"comments": "0",
"trackbacks": "0",
"date": "1303372007"
},
{
"id": "1",
"title": "티스토리 OAuth2.0 API 오픈!",
"postUrl": "http://oauth.tistory.com /1",
"visibility": "0",
"categoryId": "0",
"comments": "0",
"trackbacks": "0",
"date": "1303352668"
}
]
}
}
}
게시글 작성¶
게시글을 작성할 수 있는 API입니다. 해당 API에 관한 정보는 게시글 작성 API 를 통해 살펴보실 수 있습니다.
from pytistory import PyTistory
pytistory = PyTistory()
pytistory.configure()
response = pytistory.post.write("Post Title",
blog_name='sampleUrl',
visibility=1,
category=12,
content="Post Content",
tag=["Tag1", "Tag2"])
인자는 다음처럼 받습니다.
title: | 포스트 제목입니다. |
---|---|
blog_name: | 블로그 명입니다. 기본값은 |
target_url: | 블로그의 url입니다. deprecated된 옵션입니다. 기본값은 |
visibility: |
기본값은 |
published: | 발행 시간. 만약 설정시 예약 발행이 됨., |
category: | 카테고리를 뜻하고, |
content: | 글 내용, 기본값은 |
slogan: | 문자 주소. 이는 아마 블로그 주소 형식을 문자로 설정했을 때의 값인 듯 합니다. 기본값은 |
tag: | 게시글에 태그를 설정합니다, 기본값은 |
결과값은 아래처럼 받을 수 있습니다.
{
"status": "200",
"postId": "74",
"url": "http://sampleUrl.tistory.com/74"
}
게시글 수정¶
작성된 게시글을 수정할 수 있는 API입니다. 해당 API에 관한 정보는 게시글 수정 API 를 통해 살펴보실 수 있습니다.
from pytistory import PyTistory
pytistory = PyTistory()
pytistory.configure()
response = pytistory.post.modify("Post Title",
1,
blog_name='sampleUrl',
visibility=1,
category=12,
content="Post Content",
tag=["Tag1", "Tag2"])
인자값은 위의 게시글 작성 API에서, 두가지 변경사항만 있습니다.
published
값을 설정할 수 없고, int
타입의 post_id
를 추가적으로 전달해주어야 합니다.
결과값은 아래처럼 받을 수 있습니다.
{
"status": "200",
"postId": "74",
"url": "http://sampleUrl.tistory.com/74"
}
글 읽기¶
단일 게시글을 읽을 수 있는 API입니다. 해당 API에 관한 정보는 글 읽기 API 를 통해 살펴보실 수 있습니다.
from pytistory import PyTistory
pytistory = PyTistory()
pytistory.configure()
response = pytistory.post.read(1, blog_name='sampleUrl')
인자값은 blog_name
과 post_id
만을 받습니다.
결과값은 아래처럼 받을 수 있습니다.
{
"status": "200",
"item": {
"url": "http://oauth.tistory.com",
"secondaryUrl": "",
"id": "1",
"title": "티스토리 OAuth2.0 API 오픈!",
"content":
"안녕하세요 Tistory API 입니다.<br><br>이번에 Third-party Developer 용 <b>Tistory OAuth 2.0 API</b> 가 오픈됩니다.",
"categoryId": "0",
"postUrl": "http://oauth.tistory.com/1",
"visibility": "0",
"acceptComment": "1",
"acceptTrackback": "1",
"tags": {
"tag": ["open", "api"]
},
"comments": "0",
"trackbacks": "0",
"date": "1303352668"
}
}
파일 첨부¶
파일을 첨부 할 수 있는 API입니다. 해당 API에 관한 정보는 파일 첨부 API 를 통해 살펴보실 수 있습니다.
from pytistory import PyTistory
pytistory = PyTistory()
pytistory.configure()
response = pytistory.post.attach('./path/to/uploading/file', blog_name='sampleUrl')
인자값은 파일의 경로와 블로그의 이름을 받습니다. 스트림을 통한 업로드는 추후 구현예정입니다.
결과값은 아래처럼 받을 수 있습니다.
{
"status": "200",
"url": "http://cfile6.uf.tistory.com/image/1328CE504DB79F5932B13F",
"replacer":
"%5b%23%23_1N%7ccfile6.uf%401328CE504DB79F5932B13F%7cwidth%3d\"500\"+height%3d\"300\"%7c_%23%23%5d"
}
글 삭제¶
이 API를 사용하기 위해서는 사전 협의가 필요하다고 합니다.
단일 게시글을 삭제할 수 있는 API입니다. 해당 API에 관한 정보는 글 삭제 를 통해 살펴보실 수 있습니다.
from pytistory import PyTistory
pytistory = PyTistory()
pytistory.configure()
response = pytistory.post.delete(1, blog_name='sampleUrl')
인자값은 글의 번호와 블로그의 이름을 받습니다.
결과값은 아래처럼 받을 수 있습니다.
{
"status": "200"
}
Category API¶
Category 리스트 조회¶
카테고리 목록을 가져올 수 있는 API입니다. 해당 API에 관한 정보는 카테고리 리스트 조회 API 를 통해 살펴보실 수 있습니다.
from pytistory import PyTistory
pytistory = PyTistory()
pytistory.configure()
response = pytistory.category.list(blog_name='oauth')
결과값은 아래처럼 받을 수 있습니다.
{
"status": "200",
"item": {
"url": "oauth",
"secondaryUrl": "",
"categories": {
"category": [
{
"id": "403929",
"name": "OAuth2.0 Athentication",
"parent": "",
"label": "OAuth2.0 Athentication",
"entries": "0"
},
{
"id": "403930",
"name": "Blog API Series",
"parent": "",
"label": "Blog API Series",
"entries": "0"
},
{
"id": "403931",
"name": "Post API Series",
"parent": "",
"label": "Post API Series",
"entries": "0"
},
{
"id": "403932",
"name": "Category API Series",
"parent": "",
"label": "Category API Series",
"entries": "0"
},
{
"id": "403933",
"name": "Comment API Series",
"parent": "",
"label": "Comment API Series",
"entries": "0"
},
{
"id": "403934",
"name": "Guestbook API Series",
"parent": "",
"label": "Guestbook API Series",
"entries": "0"
}
]
}
}
}
Comment API¶
게시글 댓글 정보 조회¶
단일 게시글에 포함된 댓글 정보를 조회할 수 있는 API입니다. 해당 API에 관한 정보는 단일 게시글 댓글 조회 API 를 통해 살펴보실 수 있습니다.
from pytistory import PyTistory
pytistory = PyTistory()
pytistory.configure()
response = pytistory.comment.list(4, blog_name='oauth')
결과값은 아래처럼 받을 수 있습니다.
{
"status": "200",
"item": {
"url": "http://oauth.tistory.com/4",
"secondaryUrl": "",
"postId": "4",
"totalCount": "3",
"comments": {
"comment": [
{
"id": "8176918",
"date": "1303796711",
"name": "지나다가",
"parentId": "",
"homepage": "http://someurl.com",
"visibility": "2",
"comment": "좋은 글 감사합니다.",
"open": "Y"
},
{
"id": "8176923",
"date": "1303796801",
"name": "글쎄요",
"parentId": "",
"homepage": "http://shesgone.com",
"visibility": "2",
"comment": " 제 홈에 와서 구경해보세요^_^",
"open": "N"
},
{
"id": "8176926",
"date": "1303796900",
"name": "Tistory API",
"parentId": "8176918",
"homepage": "http://oauth.tistory.com",
"visibility": "2",
"comment": "비루한 글에 칭찬을 하시니 몸둘바를 모르.. 지 않아!",
"open": "Y"
}
]
}
}
}
최근 댓글 조회¶
블로그내 최근 댓글을 조회할 수 있는 API입니다. 해당 API에 관한 정보는 최근 댓글 조회 API 를 통해 살펴보실 수 있습니다.
from pytistory import PyTistory
pytistory = PyTistory()
pytistory.configure()
response = pytistory.comment.newest(blog_name='oauth')
결과값은 아래처럼 받을 수 있습니다.
{
"status": "200",
"item": {
"url": "http://oauth.tistory.com",
"secondaryUrl": "",
"comments": {
"comment": [
{
"id": "8176926",
"date": "1303796900",
"postId": "4",
"name": "Tistory API",
"homepage": "http://oauth.tistory.com",
"comment": "비루한 글에 칭찬을 하시니 몸둘바를 모르.. 지 않아!",
"open": "Y",
"link": "http://oauth.tistory.com/4#comment8176926"
},
{
"id": "8176923",
"date": "1303796801",
"postId": "4",
"name": "글쎄 요",
"homepage": "http://shesgone.com",
"comment": "제 홈에 와서 구경해보세요^_^",
"open": "N",
"link": "http://oauth.tistory.com/4#comment8176923"
},
{
"id": "8176918",
"date": "1303796711",
"postId": "4",
"name": "지나다가",
"homepage": "http://someurl.com",
"comment": "좋은 글 감사합니다.",
"open": "Y",
"link": "http://oauth.tistory.com/4#comment8176918"
}
]
}
}
}
댓글 작성¶
단일 게시글 및 단일 댓글에 댓글을 작성할 수 있는 API입니다. 해당 API에 관한 정보는 댓글 작성 API 를 통해 살펴보실 수 있습니다.
from pytistory import PyTistory
pytistory = PyTistory()
pytistory.configure()
response = pytistory.comment.write(4,
'some-comment-content',
blog_name='oauth',
parent_id=12,
secret=1)
인자값은 post_id
값과 댓글의 내용을 먼저 넣어줍니다.
parent_id
댓글의 답글일 경우 설정하는 optional 값입니다.
secret
인자 경우는 1일 경우 비밀 댓글이 됩니다.
결과값은 아래처럼 받을 수 있습니다.
{
"status": "200",
"commentUrl": "http://oauth.tistory.com/4#comment8176976",
"result": "OK"
}
댓글 수정¶
이미 작성된 댓글을 수정할 수 있는 API입니다. 해당 API에 관한 정보는 댓글 수정 API 를 통해 살펴보실 수 있습니다.
from pytistory import PyTistory
pytistory = PyTistory()
pytistory.configure()
response = pytistory.comment.modify(4,
8176976,
'some-comment-content',
blog_name='oauth',
parent_id=12)
수정의 경우이므로, 게시글 id (post_id
)와 댓글 id (comment_id
), 수정할 내용을 전달해줍니다.
그 뒤로는 secret
이 빠진 점을 제외하면 댓글 작성과 동일합니다.
결과값은 아래처럼 받을 수 있습니다.
{
"status": "200",
"commentUrl": "http://oauth.tistory.com/4#comment8176976",
"result": "OK"
}
댓글 삭제¶
댓글을 삭제할 수 있는 API입니다. 해당 API에 관한 정보는 댓글 삭제 API 를 통해 살펴보실 수 있습니다.
from pytistory import PyTistory
pytistory = PyTistory()
pytistory.configure()
response = pytistory.comment.delete(4,
8176976,
blog_name='oauth')
삭제 기능이므로, 게시글 id (post_id
)와 댓글 id (comment_id
), 블로그 명(blog_name
)을 전달해줍니다.
결과값은 아래처럼 받을 수 있습니다.
{
"status": "200"
}
Guestbook API¶
방명록 목록 조회¶
블로그내 방명록을 조회할 수 있는 API입니다. 해당 API에 관한 정보는 방명록 목록 조회 API 를 통해 살펴보실 수 있습니다.
from pytistory import PyTistory
pytistory = PyTistory()
pytistory.configure()
response = pytistory.guestbook.list(blog_name='oauth')
결과값은 아래처럼 받을 수 있습니다.
{
"status": "200",
"item": {
"url": "http://oauth.tistory.com",
"secondaryUrl": "",
"page": "1",
"totalCount": "2",
"guestbooks": {
"guestbook": [
{
"id": "8177011",
"date": "1303798898",
"name": "잘못들어온 사람",
"homepage": "http://wrongway.com",
"comment": "아.. 저 여기 잘못들어왔나봐요..",
"open": "Y",
"replies": {
"reply": {
"id": "8177015",
"date": "1303799030",
"name": "Tistory API",
"parentId": "8177011",
"homepage": "http://oauth.tistory.com",
"comment": "들어올때는 마음대로 들어왔겠지만 나갈때는 아니란다",
"open": "Y"
}
}
},
{
"id": "8177008",
"date": "1303798795",
"name": "개발자",
"homepage": "http://somedeveloper.com",
"comment": "좋은 API 많이 만들어주세요!",
"open": "Y",
"replies": ""
}
]
}
}
}
방명록 작성¶
방명록 또는 방명록의 답변을 작성할 수 있는 API입니다. 해당 API에 관한 정보는 방명록 작성 API 를 통해 살펴보실 수 있습니다.
from pytistory import PyTistory
pytistory = PyTistory()
pytistory.configure()
response = pytistory.guestbook.write("잘 들렀다 가요~ :D", blog_name='oauth', parent_id=13, secret=1)
secret
인자는 1일 경우 비밀글로 작성이 됩니다.
결과값은 아래처럼 받을 수 있습니다.
{
"status": "200",
"guestbookUrl": "http://oauth.tistory.com/guestbook",
"result": "OK"
}
방명록 수정¶
이미 작성된 방명록을 수정할 수 있는 API입니다. 해당 API에 관한 정보는 방명록 수정 API 를 통해 살펴보실 수 있습니다.
from pytistory import PyTistory
pytistory = PyTistory()
pytistory.configure()
response = pytistory.guestbook.modify(13, "[수정] 잘 들렀다 가요~ :D", blog_name='oauth', parent_id=13, secret=1)
secret
인자는 1일 경우 비밀글로 작성이 됩니다.
결과값은 아래처럼 받을 수 있습니다.
{
"status": "200",
"guestbookUrl": "http://oauth.tistory.com/guestbook",
"result": "OK"
}
방명록 삭제¶
방명록을 삭제할 수 있는 API입니다. 해당 API에 관한 정보는 방명록 삭제 API 를 통해 살펴보실 수 있습니다.
from pytistory import PyTistory
pytistory = PyTistory()
pytistory.configure()
response = pytistory.guestbook.delete(13, blog_name='oauth')
인자값은 방명록의 id를 받습니다.
결과값은 아래처럼 받을 수 있습니다.
{
"status": "200"
}