npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tistory-js

v1.14.11

Published

Unofficial Tistory Blog API for Node.JS

Downloads

17

Readme

[Unofficial] Tistory.JS

Node.JS에서 사용할 수 있는 비공식 Tistory API 구현체입니다.

브라우저는 지원하지 않습니다. 🙅


Installation

$ npm install tistory-js

Tistory API V1

V1 API의 상세스펙은 티스토리 공식 도큐먼트에서 확인할 수 있습니다.

구현된 기능

현재 사용할 수 있는 기능은 다음과 같습니다.

  • [x] 블로그 정보 조회
  • [x] 게시글
    • [x] 게시글 목록 조회
    • [x] 게시글 조회
    • [x] 게시글 작성
    • [x] 게시글 수정
    • [x] 파일 업로드
  • [x] 모든 카테고리 조회
  • [x] 댓글
    • [x] 최근 댓글 목록 조회
    • [x] 게시글 댓글 목록 조회
    • [x] 게시글 댓글 작성
    • [x] 게시글 댓글 수정
    • [x] 게시글 댓글 삭제

튜토리얼

1. API 객체 생성

먼저 App IDSecret Key를 사용하여 API 객체를 생성합니다.

명시적으로 인자로써 넘기거나, 암묵적으로 환경변수를 사용할 수 있습니다.

//
// using import
import { TistoryApi } from "tistory-js/v1";

//
// using require
const { TistoryApi } = require("tistory-js/v1");

//
// 명시적으로 키를 넘깁니다.
const api = new TistoryApi({
    client: "YOUR_CLIENT_KEY",
    secret: "YOUR_SECRET_KEY",
});

/**
 * 암묵적으로 키를 넘깁니다.
 * 이 경우에는, 아래의 환경변수를 사용합니다.
 *
 *  "TISTORY_API_APP_CLIENT" : 클라이언트 키
 *  "TISTORY_API_APP_SECRET" : 비밀 키
 */
const api = new TistoryApi();

2. 코드 발급받기

티스토리에서 AccessToken을 발급받기 위해서는, 사용자가 동의했을때 부여되는 Code값이 필요합니다.

현재 Code값을 받아오기 위한 방법들은 아래와 같습니다.

  1. 유저가 승인했을 때 발생하는 리다이렉트 경로에 포함된 Code 파라미터 획득.
  2. 계정정보를 직접 입력하여 Code값 획득.

티스토리에서 공식적으로 지원하는 방법은 1 뿐입니다.

2Tistory JS 라이브러리에서 구현한 비공식 방법입니다.

/**
 * 명시적으로 계정정보를 넘겨서 코드를 얻습니다.
 */
const code: string = await api.getCodeViaAccountInfo({
    id: "TISTORY_ID",
    pw: "TISTORY_PW",
});

/**
 * 암묵적으로 계정정보를 넘겨서 코드를 얻습니다.
 * 이 경우에는, 아래의 환경변수를 사용합니다.
 *
 *  "TISTORY_API_USER_ID" : 로그인에 사용되는 아이디
 *  "TISTORY_API_USER_PW" : 로그인에 사용되는 비밀번호
 */
const code: string = await api.getCodeViaAccountInfo();

3. 액세스 토큰 발급받기

위에서 얻은 code값을 사용하여 AccessToken으로 교환받을 수 있습니다.

이렇게 취득된 AccessToken3600초동안만 유효합니다.

//
// 토큰으로 액세스 토큰 발급.
const access_token = await api.getAccessTokenViaCode(code);

4. API 사용

이 발급받은 AccessToken을 넘겨서 API를 사용할 수 있습니다! 😋

아래는 발급받은 AccessToken을 사용하여 게시글을 수정하는 예시입니다.

const res = await api.modifyPost({
    access_token,

    blogName: "YOUR_BLOG_ID",
    postId: "YOUR_POST_ID",

    title: "제목이 수정되었습니다!",
    content: "내용이 수정되었습니다!",
});