T Story(Tistory)와 WordPress 블로그 글을 API를 통해 연동하는 방법은 양쪽 플랫폼의 API를 활용하여 콘텐츠를 동기화하거나 전송하는 프로세스를 포함합니다. Tistory와 WordPress는 각각 REST API를 제공하며, 이를 통해 게시글을 가져오거나 업로드할 수 있습니다. 아래는 이를 구현하는 단계별 방법입니다. 질문이 한국어로 작성되었으므로 한국어로 간결하고 명확하게 답변하며, 검색 결과와 최신 정보를 반영합니다.
1. 준비 단계
- Tistory API 키 발급:
- Tistory 관리자 페이지에 로그인 후, Tistory Open API에서 애플리케이션을 등록합니다.
- 클라이언트 ID, 클라이언트 시크릿, 리다이렉트 URI를 발급받습니다.
- OAuth 2.0 인증을 통해 액세스 토큰을 획득합니다. (예:
https://www.tistory.com/oauth/authorize?client_id={클라이언트_ID}&redirect_uri={리다이렉트_URI}&response_type=code)
- WordPress REST API 설정:
- WordPress 4.7 이상에서는 REST API가 기본 제공됩니다. (
/wp-json/엔드포인트로 확인 가능) - 인증을 위해 Application Passwords 또는 OAuth 플러그인을 설정합니다:
- WordPress 관리자 → 사용자 → 프로필 → 애플리케이션 비밀번호 생성.
- 또는 JWT Authentication for WP REST API 플러그인을 설치하여 토큰 기반 인증을 설정.
- WordPress REST API 엔드포인트 예:
https://your-site.com/wp-json/wp/v2/posts
- WordPress 4.7 이상에서는 REST API가 기본 제공됩니다. (
- 개발 환경:
- Python, PHP, 또는 JavaScript(Node.js) 등 HTTP 요청을 처리할 수 있는 언어를 선택.
- Postman 또는 cURL로 API 요청을 테스트.
- WP-CLI(WordPress) 또는 Tistory API 문서를 참고하여 엔드포인트 확인.
2. Tistory에서 WordPress로 게시글 연동
Tistory의 게시글을 WordPress로 가져오거나 동기화하는 방법입니다.
(1) Tistory 게시글 가져오기
- API 엔드포인트:
https://www.tistory.com/apis/post/list?access_token={액세스_토큰}&blogName={블로그_이름}&page={페이지} - HTTP 메서드: GET
- 응답 형식: JSON (게시글 ID, 제목, 내용, 태그 등 포함)
- 샘플 코드 (Python):
import requests tistory_api_url = "https://www.tistory.com/apis/post/list" params = { "access_token": "your_access_token", "output": "json", "blogName": "your_blog_name", "page": 1 } response = requests.get(tistory_api_url, params=params) if response.status_code == 200: posts = response.json()["tistory"]["item"]["posts"] for post in posts: print(post["title"], post["content"]) else: print("Error:", response.status_code)
(2) WordPress에 게시글 업로드
- API 엔드포인트:
https://your-site.com/wp-json/wp/v2/posts - HTTP 메서드: POST
- 인증: 애플리케이션 비밀번호를 HTTP Basic Auth로 사용 (예:
Authorization: Basic {base64(사용자명:애플리케이션_비밀번호)}) - 샘플 코드 (Python):
import requests from base64 import b64encode wp_api_url = "https://your-site.com/wp-json/wp/v2/posts" username = "your_username" app_password = "your_application_password" credentials = b64encode(f"{username}:{app_password}".encode()).decode() headers = { "Authorization": f"Basic {credentials}", "Content-Type": "application/json" } for post in posts: # Tistory에서 가져온 게시글 data = { "title": post["title"], "content": post["content"], "status": "publish", "categories": [1], # 카테고리 ID "tags": post.get("tags", []) } response = requests.post(wp_api_url, headers=headers, json=data) if response.status_code == 201: print(f"Posted: {post['title']}") else: print("Error:", response.status_code, response.text)
(3) 자동화
- Python 스크립트를 크론잡(Cron Job) 또는 GitHub Actions에 설정하여 주기적으로 실행.
- Tistory 게시글의 수정 날짜(
modified)를 확인하여 새로운 게시글만 업로드하도록 필터링.
3. WordPress에서 Tistory로 게시글 연동
WordPress 게시글을 Tistory로 업로드하는 방법입니다.
(1) WordPress 게시글 가져오기
- API 엔드포인트:
https://your-site.com/wp-json/wp/v2/posts - HTTP 메서드: GET
- 샘플 코드 (Python):
wp_api_url = "https://your-site.com/wp-json/wp/v2/posts" response = requests.get(wp_api_url) if response.status_code == 200: wp_posts = response.json() for post in wp_posts: print(post["title"]["rendered"], post["content"]["rendered"])
(2) Tistory에 게시글 업로드
- API 엔드포인트:
https://www.tistory.com/apis/post/write - HTTP 메서드: POST
- 파라미터:
access_token: 액세스 토큰blogName: 블로그 이름title: 게시글 제목content: 게시글 내용visibility: 공개 여부 (0: 비공개, 1: 보호, 3: 공개)category: 카테고리 ID (선택)tag: 태그 (선택)
- 샘플 코드 (Python):
tistory_post_url = "https://www.tistory.com/apis/post/write" for post in wp_posts: data = { "access_token": "your_access_token", "output": "json", "blogName": "your_blog_name", "title": post["title"]["rendered"], "content": post["content"]["rendered"], "visibility": 3, "tag": ",".join(post.get("tags", [])) } response = requests.post(tistory_post_url, data=data) if response.status_code == 200: print(f"Posted to Tistory: {post['title']['rendered']}") else: print("Error:", response.status_code, response.text)
4. 고려 사항
- 인증 보안:
- Tistory는 OAuth 2.0, WordPress는 애플리케이션 비밀번호 또는 JWT를 사용하므로, API 키와 토큰을 환경 변수(
.env) 또는 보안 저장소에 저장. - HTTPS를 사용하여 데이터 전송 보안 유지.
- Tistory는 OAuth 2.0, WordPress는 애플리케이션 비밀번호 또는 JWT를 사용하므로, API 키와 토큰을 환경 변수(
- 제한 및 쿼터:
- Tistory API는 요청 횟수 제한이 있을 수 있으므로, 문서를 확인하고
rate limiting에 대비. - WordPress REST API는 기본적으로 페이지당 100개 항목 반환(최대 500개,
per_page파라미터로 조정).
- Tistory API는 요청 횟수 제한이 있을 수 있으므로, 문서를 확인하고
- 콘텐츠 형식:
- Tistory와 WordPress는 HTML/Markdown 형식이 다를 수 있으므로,
html2text또는markdownify라이브러리로 콘텐츠 변환. - 이미지나 미디어는 별도로 업로드 후 URL을 매핑해야 함 (Tistory:
/apis/post/attach, WordPress:/wp/v2/media).
- Tistory와 WordPress는 HTML/Markdown 형식이 다를 수 있으므로,
- 에러 처리:
- HTTP 상태 코드(401, 429 등)를 확인하여 인증 오류나 요청 제한 처리.
- Tistory API 응답에서
error_message필드 확인.
5. 대안: 플러그인 활용
API를 직접 다루는 대신, 플러그인을 사용할 수 있습니다:
- WordPress: WPGetAPI 또는 Jetpack 플러그인을 통해 외부 API(Tistory) 데이터 가져오기.
- Tistory: IFTTT 또는 Zapier를 사용하여 RSS 피드를 통해 WordPress와 연동.
- 예: WordPress 새 게시글 → RSS → Zapier → Tistory 게시글 생성.
- 단점: 플러그인/서드파티 서비스는 유연성이 낮고 비용이 발생할 수 있음.
6. 샘플 워크플로우
- Tistory에서 새 게시글 작성.
- Python 스크립트가 매일 1회 Tistory API를 호출하여 새 게시글 확인.
- 새 게시글을 WordPress REST API로 전송하여 업로드.
- 반대 방향(WordPress → Tistory)도 동일한 방식으로 설정.
- GitHub Actions로 스크립트 자동 실행, Slack으로 성공/실패 알림 설정.
7. 추가 팁
- 캐싱: Tistory/WordPress API 응답을 Redis 또는 WordPress Transient API로 캐싱하여 성능 최적화.
- 테스트: Postman으로 각 API 엔드포인트를 테스트한 후 코드를 작성.
- 문서 참고:
- Tistory API: https://www.tistory.com/guide/api
- WordPress REST API: https://developer.wordpress.org/rest-api/
- 문제 해결: Tistory API는 문서가 제한적일 수 있으므로, X에서 최신 사례 검색(
#TistoryAPI) 또는 xAI 지원 문의.
참고: 검색 결과에 Tistory API와 WordPress REST API를 직접 연동한 사례는 없었으나, WordPress REST API의 일반적인 사용 사례(예: USA Today, New York Times)와 통합 원리를 적용했습니다. Tistory API는 한국 중심 플랫폼이므로, 한국어 커뮤니티(예: 네이버 카페, 티스토리 공식 블로그)에서 추가 사례를 찾을 수 있습니다.
궁금한 점이 더 있다면 구체적인 요구사항(예: 특정 언어, 양방향 동기화 여부)을 말씀해주세요!
'T Story and Blog' 카테고리의 다른 글
| MACBOOK PRO RETINA DISPLAY 복구(1)-A1398 (12) | 2025.05.02 |
|---|---|
| Thunderbolt 4 vs USB4, 저렴하고 성능 우수한 Thunderbolt 4 제품 추천 (6) | 2025.05.01 |
| 2024년 아마존닷컴에서 “많이 팔리거나 평점이 좋은” 휴대폰 관련 용품 (2) | 2025.04.29 |
| Grok의 응답(예: 텍스트, 코드, 마크 다운 형식)을 형식 그대로 복사하여 붙여 넣는 방법 (0) | 2025.04.24 |
| T Story와 WordPress 블로그 글 연동하기(1) - RSS (2) | 2025.04.23 |