PyTistory๋ ํฐ์คํ ๋ฆฌ ์คํ API ๊ฐ์ด๋ ๋ฅผ ์ฐธ๊ณ ํ์ฌ Python์ผ๋ก ์์ฑํ ํฐ์คํ ๋ฆฌ API ํด๋ผ์ด์ธํธ์ ๋๋ค. ํฐ์คํ ๋ฆฌ ์คํ API ๊ฐ์ด๋ ์ธ์ฆ ๋ฐฉ์ ์ค Client-side flow ๋ฐฉ์์ ๋ฐ๋ผ ๊ตฌํ๋์์ต๋๋ค. ์์ธํ ์ฌ์ฉ๋ฒ์ PyTistory Documentation ์์ ํ์ธํ์ค ์ ์์ต๋๋ค.
pytistory๋ pip
๋ฅผ ํตํด ์ค์นํ ์ ์์ต๋๋ค.
$ pip install pytistory
์ธ์ฆ์ ๋ณด๋ ๋ค์๊ณผ ๊ฐ์ ์ฐ์ ์์๋ฅผ ํตํด ์ ์ฉ๋ฉ๋๋ค.
- ์ง์ ์ค์ ํ๋
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
๋ง์ ์ค์ ํฉ๋๋ค.
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
https://www.tistory.com/apis/kind/action ์ ๊ฐ์ api๋ฅผ ํธ์ถํ ๊ฒฝ์ฐ ์๋์ฒ๋ผ ํธ์ถํฉ๋๋ค.
from pytistory import PyTistory
pytistory = PyTistory()
pytistory.configure()
response = pytistory.kind.action(args...)
์์๋ก ๋ธ๋ก๊ทธ ์ ๋ณด๋ฅผ ๋ฐ์์ค๋ ์ฝ๋๋ ์๋์ ๊ฐ์ต๋๋ค.
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"
}
}
]
}
์ด ํ๋ก์ ํธ๋ ๋ถ์กฑํ ์ ์ด ๋ง์ต๋๋ค. Contribution์ ์ธ์ ๋ ํ์์ ๋๋ค. ํน์ ์ค๋ฅ, ๋ฒ๊ทธ ํน์ ์ ๋ฐ์ดํธ๊ฐ ํ์ํ ์ ์ด ์์ผ์๋ค๋ฉด PR ๋๋ Issue ๋ฅผ ํตํด ์ธ์ ๋ ์ง ์๋ ค์ฃผ์ธ์. ๐
Copyright (c) 2018 JeongUkJae. MIT License.