- TISTORY 오픈 API 앱 등록.
- 앱 등록
서비스 명 입력
서비스 URL 및 CallBack에 TISTORY 주소 입력한다.
등록
등록 완료 후 App ID 및 Secret Key 사용 가능.
위의 정보들이 Python에서 필요하다.
앱 등록 시 입력한 정보로 아래 값 설정.
g_client_id =
g_redirect_uri =
g_user_id =
g_password =
Python 소스
import requests
import json
import re
#Open API 앱 등록후 App 아이디 설정
g_client_id = {App ID}
#Open API 앱 등록후 입력한 CallBack 설정
g_redirect_uri = {CallBack}
g_oauth_url = "https://www.tistory.com/oauth/authorize?client_id="+g_client_id+"&redirect_uri="+g_redirect_uri+"&response_type=token"
#TISTORY ID
g_user_id = {TISTORY ID}
#TISTORY PASSWORD
g_password = {TISTORY PASSWORD}
print(g_oauth_url)
res = requests.get(g_oauth_url)
print(res.status_code)
print(res.headers['Set-Cookie'])
kakao_cookie = res.headers['Set-Cookie'].replace("; path=/",'')
print(kakao_cookie)
print(res.url)
headers = {
'Accept' : 'text/html, application/xhtml+xml, image/jxr, */*',
'Accept-Encoding' : 'gzip, deflate',
'Accept-Language' : 'ko, en-US; q=0.8, en; q=0.6, zh-Hans-CN; q=0.4, zh-Hans; q=0.2',
'Cache-Control' : 'no-cache',
'Connection' : 'Keep-Alive',
'Content-Type' : 'application/x-www-form-urlencoded',
'Cookie' : kakao_cookie,
'Host' : 'www.tistory.com',
'Referer' : res.url,
'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko'
}
login_data = {
'fp' : 'a668ac102f81b86f521c07dfb6dc992c',
'keepLogin' : 'on',
'loginId' : g_user_id,
'password' : g_password,
'redirectUrl' : res.url
}
res = requests.post('https://www.tistory.com/auth/login', headers=headers, data=login_data)
print(res.url)
match = re.match('(.*?)access_token=(?P<access_token>.*?)&state=', res.url)
gd = match.groupdict()
access_token = gd['access_token']
print(access_token)
python 실행 후 access token 확인
관련 소스
https://github.com/leechul/py_tistory
leechul/py_tistory
Tistory OpenAPI Python automation. Contribute to leechul/py_tistory development by creating an account on GitHub.
github.com
처음 사용시 이메일에서 로그인 확인하여주어야 한다.
'Python' 카테고리의 다른 글
Python 관련 문의 stackoverflow 에 문의 결과... (0) | 2019.10.28 |
---|---|
python 특수 기호 의미 (0) | 2019.10.24 |
ModuleNotFoundError: No module named 'requests' (0) | 2019.10.23 |
Windows Python 설치 및 Path 잡아주기 (0) | 2019.10.23 |
python 개발환경 ATOM IDE 사용. (0) | 2019.10.23 |