티스토리 API 사용을 위한 준비

    https://www.tistory.com/guide/api/manage/register

     

    Tistory

    좀 아는 블로거들의 유용한 이야기

    www.tistory.com

    이곳에 앱을 등록하고 나면 App ID와 Secret Key 가 만들어진다.

    access token을 발급받기 위해서는 auth_code가 필요한데

     

    https://www.tistory.com/oauth/authorize?client_id={App ID}&redirect_uri={생성한 블로그 주소}&response_type=code&state=someValue 

     

    생성한 블로그 주소는 서비스 URL 과 CallBack 에 등록한 주소이다.

     

    호출 후 auth_code 를 복사하여 넣고 access_token을 얻는다.

     

    tistory_auth_url = ' https://www.tistory.com/oauth/access_token?' 
    client_id = 'App ID'
    client_secret = 'secret key'
    auth_code = '인증후에 나오는 code'
    redirect_uri = '생성한 블로그 주소'

    def get_access_token():
        """get tistory access token """
        data = f'{tistory_auth_url}client_id={client_id}&client_secret={client_secret}&redirect_uri={redirect_uri}&code={auth_code}&grant_type=authorization_code'
        return  requests.get(data).content.decode('utf-8')

    if __name__ == "__main__":
        token = get_access_token()
        print(token)

     

    이렇게 생성된 토큰으로 블로그에 글을 올릴 준비가 되었다.

     

    'Chat GPT' 카테고리의 다른 글

    스테이블 디퓨전으로 그림 그리기  (0) 2023.07.03
    음성 비서 만들기  (0) 2023.07.03
    이미지 크롤링을 해보자  (0) 2023.07.03

    댓글