티스토리 뷰

  • 티스토리에 게시글을 업로드하는 코드
  • 접속 토큰(access_token)이 필요함.
  • 티스토리 Open API 활용

 

<Main Source>

                    param1 = {
                        'title': titleString,
                        'content': contentString1,
                    }
                    ti1.UploadArticle(param1)

 

<Method>

    def UploadArticle(self, params=None):
        url0 = 'https://www.tistory.com/apis/post/write'
        appID =  cConstants.APPID_TISTORY
        secretKey = cConstants.SECRETKEY_TISTORY

        blogName = self.BLOGNAME
        title = 'title - Test10'
        content = 'conent - Test01'
        visibility = 0 # 0:private, 3: open, 1:protected
        categoryID = self.CATEGORYID

        if not params:
            param1 = {
                'access_token': self.AccessToken,
                'blogName' : blogName,
                'title': title,
                'content': content,
                'visibility': visibility,
                'category': categoryID,
                'acceptComment': 0
            }
        else:
            param1 = params
            if not params.get('title'): return None
            if not params.get('content'): return None
            if not params.get('blogName'): params['blogName'] = blogName
            if not params.get('visibility'): params['visibility'] = visibility
            if not params.get('category'): params['category'] = categoryID
            param1 = params

        param1['access_token'] = self.AccessToken
        print(param1)

        res1 = requests.post(url0, params=param1)
        print("[UploadArticle()]", res1.text)
반응형
반응형
250x250
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함